
template <typename T> bool boost::pseudoprime(const T& n, const T& k) { typedef boost::operators<T> operatorT; BOOST_STATIC_ASSERT(is_integral<T>::value); // static assert 1. BOOST_STATIC_ASSERT((is_base_of<operatorT, T>::value)); // static assert 2. BOOST_ASSERT (n > T(2) && n % T(2) != 0); return modular_expo(k, n-1, n) != T(1) % n ? true : false; } now in vistual studio 2005 sp1 and visual studio 2008 beta the part "is_base_of<operatorT, T>::value" does not work if T happens to be an int or long due to "error C2803: 'operator --' must have at least one formal parameter of class type". I want to use enable_if to enable the STATIC_ASSERT only if T is NOT an arithmetic type for static assert 2. How would i go about doing that?

on Wed Sep 26 2007, "chun ping wang" <cablepuff-AT-gmail.com> wrote:
template <typename T> bool boost::pseudoprime(const T& n, const T& k) { typedef boost::operators<T> operatorT; BOOST_STATIC_ASSERT(is_integral<T>::value); // static assert 1. BOOST_STATIC_ASSERT((is_base_of<operatorT, T>::value)); // static assert 2. BOOST_ASSERT (n > T(2) && n % T(2) != 0); return modular_expo(k, n-1, n) != T(1) % n ? true : false; }
now in vistual studio 2005 sp1 and visual studio 2008 beta the part "is_base_of<operatorT, T>::value" does not work if T happens to be an int or long due to "error C2803: 'operator --' must have at least one formal parameter of class type". I want to use enable_if to enable the STATIC_ASSERT only if T is NOT an arithmetic type for static assert 2.
enable_if can't "enable static asserts" in any sense that I understand. What are you really trying to do? Try to describe it without mentioning enable_if or STATIC_ASSERT. Just talk about the behavior you want. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com The Astoria Seminar ==> http://www.astoriaseminar.com

what i want to do is if type "T" happens to be a integeral type *or* a class type that inherits from boost::operators than let the function compile otherwise a compile time error appears. Basically T is any integeral type or any class type that derives from boost::operators. On 9/26/07, David Abrahams <dave@boost-consulting.com> wrote:
on Wed Sep 26 2007, "chun ping wang" <cablepuff-AT-gmail.com> wrote:
template <typename T> bool boost::pseudoprime(const T& n, const T& k) { typedef boost::operators<T> operatorT; BOOST_STATIC_ASSERT(is_integral<T>::value); // static assert 1. BOOST_STATIC_ASSERT((is_base_of<operatorT, T>::value)); // static assert 2. BOOST_ASSERT (n > T(2) && n % T(2) != 0); return modular_expo(k, n-1, n) != T(1) % n ? true : false; }
now in vistual studio 2005 sp1 and visual studio 2008 beta the part "is_base_of<operatorT, T>::value" does not work if T happens to be an int or long due to "error C2803: 'operator --' must have at least one formal parameter of class type". I want to use enable_if to enable the STATIC_ASSERT only if T is NOT an arithmetic type for static assert 2.
enable_if can't "enable static asserts" in any sense that I understand. What are you really trying to do? Try to describe it without mentioning enable_if or STATIC_ASSERT. Just talk about the behavior you want.
-- Dave Abrahams Boost Consulting http://www.boost-consulting.com
The Astoria Seminar ==> http://www.astoriaseminar.com
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

this question also stems from compiler error generated in microsoft visual studio 2005 sp1 and microsof visual studio 2008. It compiles fine under cygwin and mingw. template <typename T> bool boost::pseudoprime(const T& n, const T& k) { typedef boost::operators<T> operatorT; BOOST_STATIC_ASSERT(is_integral<T>::value || (is_base_of<operatorT, T>::value)); // mingw says its k, microsoft complains about it. BOOST_ASSERT (n > T(2) && n % T(2) != 0); return modular_expo(k, n-1, n) != T(1) % n ? true : false; } Just trying to get a compiler work around. On 9/26/07, chun ping wang <cablepuff@gmail.com> wrote:
what i want to do is if type "T" happens to be a integeral type *or* a class type that inherits from boost::operators than let the function compile otherwise a compile time error appears. Basically T is any integeral type or any class type that derives from boost::operators.
On 9/26/07, David Abrahams <dave@boost-consulting.com> wrote:
on Wed Sep 26 2007, "chun ping wang" <cablepuff-AT-gmail.com> wrote:
template <typename T> bool boost::pseudoprime(const T& n, const T& k) { typedef boost::operators<T> operatorT; BOOST_STATIC_ASSERT(is_integral<T>::value); // static assert 1. BOOST_STATIC_ASSERT((is_base_of<operatorT, T>::value)); // static assert 2. BOOST_ASSERT (n > T(2) && n % T(2) != 0); return modular_expo(k, n-1, n) != T(1) % n ? true : false; }
now in vistual studio 2005 sp1 and visual studio 2008 beta the part "is_base_of<operatorT, T>::value" does not work if T happens to be an int or long due to "error C2803: 'operator --' must have at least one formal parameter of class type". I want to use enable_if to enable the STATIC_ASSERT only if T is NOT an arithmetic type for static assert 2.
enable_if can't "enable static asserts" in any sense that I understand. What are you really trying to do? Try to describe it without mentioning enable_if or STATIC_ASSERT. Just talk about the behavior you want.
-- Dave Abrahams Boost Consulting http://www.boost-consulting.com
The Astoria Seminar ==> http://www.astoriaseminar.com
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

on Wed Sep 26 2007, "chun ping wang" <cablepuff-AT-gmail.com> wrote:
what i want to do is if type "T" happens to be a integeral type or a class type that inherits from boost::operators than let the function compile otherwise a compile time error appears.
I could tell you how, but it seems ill-advised. I really doubt you want to fail compilation if someone passes you a class type that acts just like int, but that isn't written using boost::operators. Are you sure that's what you want? -- Dave Abrahams Boost Consulting http://www.boost-consulting.com

hmm that is what i want for now... (i might change it later). I want to know to keept it in back of my head. Thanks. On 10/1/07, David Abrahams <dave@boost-consulting.com> wrote:
on Wed Sep 26 2007, "chun ping wang" <cablepuff-AT-gmail.com> wrote:
what i want to do is if type "T" happens to be a integeral type or a class type that inherits from boost::operators than let the function compile otherwise a compile time error appears.
I could tell you how, but it seems ill-advised. I really doubt you want to fail compilation if someone passes you a class type that acts just like int, but that isn't written using boost::operators. Are you sure that's what you want?
-- Dave Abrahams Boost Consulting http://www.boost-consulting.com
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

on Mon Oct 01 2007, "chun ping wang" <cablepuff-AT-gmail.com> wrote:
hmm that is what i want for now... (i might change it later). I want to know to keept it in back of my head. Thanks.
On 10/1/07, David Abrahams < dave@boost-consulting.com> wrote:
on Wed Sep 26 2007, "chun ping wang" < cablepuff-AT-gmail.com> wrote:
> what i want to do is if type "T" happens to be a integeral type or a class type that inherits > from boost::operators than let the function compile otherwise a > compile time error appears.
I could tell you how, but it seems ill-advised. I really doubt you want to fail compilation if someone passes you a class type that acts just like int, but that isn't written using boost::operators. Are you sure that's what you want?
// untested template <class T, class U> char (& is_op_test(operators<T,U> const&) )[2] template <class T> char is_op_test(T const&); template<class T> T const& make(); template <class T> struct is_operators : mpl::bool_<(sizeof(is_op_test(make<T>())) == 2)> {}; template <class T> typename enable_if<mpl::or_<boost::is_integral<T>, is_operators<T> >, return_type>::type f(T x) { ... } -- Dave Abrahams Boost Consulting http://www.boost-consulting.com

hmm doesn't work. g++.exe -Wall -D__DEBUG__ -c ./cs512/c++/cppdef/BitOperation.cpp -o ./lib/BitOp eration.o -I"C:/Boost/include" -I"./bigint/c++" -fexceptions -fverbose-asm -f expensive-optimizations -O3 -pg -g3 ./cs512/c++/cppdef/../MyOperators.hpp:22: error: expected initializer before 'te mplate' ./cs512/c++/cppdef/BitOperation.cpp:44: error: 'return_type' was not declared in this scope ./cs512/c++/cppdef/BitOperation.cpp:44: error: template argument 2 is invalid ./cs512/c++/cppdef/BitOperation.cpp:45: error: expected initializer before 'Log2 ' ./cs512/c++/cppdef/BitOperation.cpp:151: error: 'return_type' was not declared i n this scope ./cs512/c++/cppdef/BitOperation.cpp:151: error: template argument 2 is invalid ./cs512/c++/cppdef/BitOperation.cpp:152: error: expected initializer before 'boo st' heres the code .. typename boost::enable_if<boost::mpl::or_<boost::is_arithmetic<T>, boost::is_operators<T> >, return_type>::type // BitOperation.cpp line 44. namespace boost { // line 18 of MyOperators.hpp template <class T, class U> char (& is_op_test(boost::operators<T,U> const&) )[2] template <class T> char is_op_test(T const&); // line 24 of MyOperators.hpp } I pass T as an int which should pass the first test. On 10/1/07, David Abrahams <dave@boost-consulting.com> wrote:
on Mon Oct 01 2007, "chun ping wang" <cablepuff-AT-gmail.com> wrote:
hmm that is what i want for now... (i might change it later). I want to know to keept it in back of my head. Thanks.
On 10/1/07, David Abrahams < dave@boost-consulting.com> wrote:
on Wed Sep 26 2007, "chun ping wang" < cablepuff-AT-gmail.com> wrote:
> what i want to do is if type "T" happens to be a integeral type or a class type that inherits > from boost::operators than let the function compile otherwise a > compile time error appears.
I could tell you how, but it seems ill-advised. I really doubt you want to fail compilation if someone passes you a class type that acts just like int, but that isn't written using boost::operators. Are you sure that's what you want?
// untested template <class T, class U> char (& is_op_test(operators<T,U> const&) )[2]
template <class T> char is_op_test(T const&);
template<class T> T const& make();
template <class T> struct is_operators : mpl::bool_<(sizeof(is_op_test(make<T>())) == 2)> {};
template <class T> typename enable_if<mpl::or_<boost::is_integral<T>, is_operators<T> >, return_type>::type f(T x) { ... }
-- Dave Abrahams Boost Consulting http://www.boost-consulting.com
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

the error was a missing semicolon after declaration of the array. typename boost::enable_if<boost::mpl::or_<boost::is_arithmetic<T>, boost::is_operators<T> >, return_type>::type // line 44. ./cs512/c++/cppdef/BitOperation.cpp:44: error: 'return_type' was not declared in this scope ./cs512/c++/cppdef/BitOperation.cpp:44: error: template argument 2 is invalid ./cs512/c++/cppdef/BitOperation.cpp:45: error: expected initializer before 'Log2 ' On 10/3/07, chun ping wang <cablepuff@gmail.com> wrote:
hmm doesn't work. g++.exe -Wall -D__DEBUG__ -c ./cs512/c++/cppdef/BitOperation.cpp -o ./lib/BitOp eration.o -I"C:/Boost/include" -I"./bigint/c++" -fexceptions -fverbose-asm -f expensive-optimizations -O3 -pg -g3 ./cs512/c++/cppdef/../MyOperators.hpp:22: error: expected initializer before 'te mplate' ./cs512/c++/cppdef/BitOperation.cpp:44: error: 'return_type' was not declared in this scope ./cs512/c++/cppdef/BitOperation.cpp:44: error: template argument 2 is invalid ./cs512/c++/cppdef/BitOperation.cpp:45: error: expected initializer before 'Log2 ' ./cs512/c++/cppdef/BitOperation.cpp:151: error: 'return_type' was not declared i n this scope ./cs512/c++/cppdef/BitOperation.cpp:151: error: template argument 2 is invalid ./cs512/c++/cppdef/BitOperation.cpp:152: error: expected initializer before 'boo st'
heres the code .. typename boost::enable_if<boost::mpl::or_<boost::is_arithmetic<T>, boost::is_operators<T> >, return_type>::type // BitOperation.cpp line 44.
namespace boost { // line 18 of MyOperators.hpp template <class T, class U> char (& is_op_test(boost::operators<T,U> const&) )[2]
template <class T> char is_op_test(T const&); // line 24 of MyOperators.hpp }
I pass T as an int which should pass the first test.
On 10/1/07, David Abrahams <dave@boost-consulting.com> wrote:
on Mon Oct 01 2007, "chun ping wang" <cablepuff-AT-gmail.com> wrote:
hmm that is what i want for now... (i might change it later). I want to know to keept it in back of my head. Thanks.
On 10/1/07, David Abrahams < dave@boost-consulting.com> wrote:
on Wed Sep 26 2007, "chun ping wang" < cablepuff-AT-gmail.com > wrote:
> what i want to do is if type "T" happens to be a integeral type or a class type that inherits > from boost::operators than let the function compile otherwise a > compile time error appears.
I could tell you how, but it seems ill-advised. I really doubt you want to fail compilation if someone passes you a class type that acts just like int, but that isn't written using boost::operators. Are you sure that's what you want?
// untested template <class T, class U> char (& is_op_test(operators<T,U> const&) )[2]
template <class T> char is_op_test(T const&);
template<class T> T const& make();
template <class T> struct is_operators : mpl::bool_<(sizeof(is_op_test(make<T>())) == 2)> {};
template <class T> typename enable_if<mpl::or_<boost::is_integral<T>, is_operators<T> >, return_type>::type f(T x) { ... }
-- Dave Abrahams Boost Consulting http://www.boost-consulting.com
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

hey i got everything to work.. i realize after reading the doc return_type is the type you want to return.... On 10/3/07, chun ping wang <cablepuff@gmail.com> wrote:
the error was a missing semicolon after declaration of the array.
typename boost::enable_if<boost::mpl::or_<boost::is_arithmetic<T>, boost::is_operators<T> >, return_type>::type // line 44.
./cs512/c++/cppdef/BitOperation.cpp:44: error: 'return_type' was not declared in this scope ./cs512/c++/cppdef/BitOperation.cpp:44: error: template argument 2 is invalid ./cs512/c++/cppdef/BitOperation.cpp:45: error: expected initializer before 'Log2 '
On 10/3/07, chun ping wang <cablepuff@gmail.com> wrote:
hmm doesn't work. g++.exe -Wall -D__DEBUG__ -c ./cs512/c++/cppdef/BitOperation.cpp -o ./lib/BitOp eration.o -I"C:/Boost/include" -I"./bigint/c++" -fexceptions -fverbose-asm -f expensive-optimizations -O3 -pg -g3 ./cs512/c++/cppdef/../MyOperators.hpp:22: error: expected initializer before 'te mplate' ./cs512/c++/cppdef/BitOperation.cpp:44: error: 'return_type' was not declared in this scope ./cs512/c++/cppdef/BitOperation.cpp:44: error: template argument 2 is invalid ./cs512/c++/cppdef/BitOperation.cpp:45: error: expected initializer before 'Log2 ' ./cs512/c++/cppdef/BitOperation.cpp:151: error: 'return_type' was not declared i n this scope ./cs512/c++/cppdef/BitOperation.cpp:151: error: template argument 2 is invalid ./cs512/c++/cppdef/BitOperation.cpp:152: error: expected initializer before 'boo st'
heres the code .. typename boost::enable_if<boost::mpl::or_<boost::is_arithmetic<T>, boost::is_operators<T> >, return_type>::type // BitOperation.cpp line 44.
namespace boost { // line 18 of MyOperators.hpp template <class T, class U> char (& is_op_test(boost::operators<T,U> const&) )[2]
template <class T> char is_op_test(T const&); // line 24 of MyOperators.hpp }
I pass T as an int which should pass the first test.
On 10/1/07, David Abrahams <dave@boost-consulting.com> wrote:
on Mon Oct 01 2007, "chun ping wang" <cablepuff-AT-gmail.com> wrote:
hmm that is what i want for now... (i might change it later). I want to know to keept it in back of my head. Thanks.
On 10/1/07, David Abrahams < dave@boost-consulting.com> wrote:
on Wed Sep 26 2007, "chun ping wang" < cablepuff-AT-gmail.com > wrote:
> what i want to do is if type "T" happens to be a integeral type or a class type that inherits > from boost::operators than let the function compile otherwise a > compile time error appears.
I could tell you how, but it seems ill-advised. I really doubt you want to fail compilation if someone passes you a class type that acts just like int, but that isn't written using boost::operators. Are you sure that's what you want?
// untested template <class T, class U> char (& is_op_test(operators<T,U> const&) )[2]
template <class T> char is_op_test(T const&);
template<class T> T const& make();
template <class T> struct is_operators : mpl::bool_<(sizeof(is_op_test(make<T>())) == 2)> {};
template <class T> typename enable_if<mpl::or_<boost::is_integral<T>, is_operators<T> >, return_type>::type f(T x) { ... }
-- Dave Abrahams Boost Consulting http://www.boost-consulting.com
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
chun ping wang
-
David Abrahams