[boost-users] enable_if and checking if class derives from boost::operators does not work.
namespace boost { template <class T, class U> char (& is_op_test(boost::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 : boost::mpl::bool_<(sizeof(is_op_test(make<T>())) == 2)> {}; } and this function declaration. template <typename T, template <typename ELEM, typename = std::allocator<ELEM> > class CONT
typename boost::enable_if<boost::mpl::or_<boost::is_integral<T>, boost:: is_operators<T> >, CONT<T> >::type primelist(const T& MAX_BOUND, const T& K, boost::function<bool(const T&, const T&)> f); BigInteger class declaration looks like this.. class BigInteger : public BigUnsigned, boost::operators<BigInteger>, boost::operators<BigInteger, int> { }; I compile with T = int and it works. When i compile with T = BigInteger I get the following errors. on visual c++. error C2770: invalid explicit template argument(s) for 'boost::enable_if<boost::mpl::or_<boost::is_integral<T>,boost::is_operators<T>
,CONT<T>>::type primelist(const T &,const T &,boost::function<bool(const T &,const T &)>)' ./cs512/c++/primeMain.cpp(24) : see declaration of 'primelist'"
on mingw dev-cpp i get this error. unable to find function.... In both cases passing BigInteger does not work. thanks for the help. BigInteger does derive from boost::operators and theirs two overload.
on Fri Oct 12 2007, "chun ping wang" <cablepuff-AT-gmail.com> wrote:
namespace boost { template <class T, class U> char (& is_op_test(boost::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 : boost::mpl::bool_<(sizeof(is_op_test(make<T>())) == 2)> {}; }
You should not be creating definitions in namespace boost. Also, I'll advise against checking for derivation from operators<T,U>; There's probably a much better way to do what you are trying to do, whatever it is.
and this function declaration. template <typename T, template <typename ELEM, typename = std::allocator<ELEM> > class CONT
typename boost::enable_if<boost::mpl::or_<boost::is_integral<T>, boost:: is_operators<T> >, CONT <T> >::type primelist(const T& MAX_BOUND, const T& K, boost::function<bool(const T&, const T&)> f);
BigInteger class declaration looks like this..
class BigInteger : public BigUnsigned, boost::operators<BigInteger>, boost::operators<BigInteger, int> { };
I compile with T = int and it works.
When i compile with T = BigInteger I get the following errors.
on visual c++. error C2770: invalid explicit template argument(s) for 'boost::enable_if<boost::mpl::or_ <boost::is_integral<T>,boost::is_operators<T> >,CONT<T>>::type primelist(const T &,const T &,boost::function<bool(const T &,const T &)>)' ./cs512/c++/primeMain.cpp(24) : see declaration of 'primelist'"
on mingw dev-cpp i get this error. unable to find function....
In both cases passing BigInteger does not work.
You haven't shown the call that produces the error, and you haven't shown the full error. I suggest reducing your problem to a *minimal* complete example (one .cpp file) and posting that. The most obvious problem you have is that instantiating is_operator<BigInteger> is likely to cause an overloading ambiguity because BigInteger is derived from two different operator<T,U> specializations. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com
error: ./cs512/c++/primeMain.cpp(65) : error C2770: invalid explicit template argument(s) for 'boost::enable_if<boost::mpl::or_<boost::is_integral<T>,algocpw::is_operators<T>>,void>::type test_operators(void)' ./cs512/c++/primeMain.cpp(58) : see declaration of 'test_operators' ./cs512/c++/primeMain.cpp(66) : error C2770: invalid explicit template argument(s) for 'boost::enable_if<boost::mpl::or_<boost::is_integral<T>,algocpw::is_operators<T>>,void>::type test_operators(void)' ./cs512/c++/primeMain.cpp(58) : see declaration of 'test_operators' If that is the problem. Is their a way to fix is_operators to say that 1.) boost::operators<T> is at least one of the base class of MyInt. or 2.) A Way to have my class pass the "is_integral<T>" test. A user defined data type that acts like an integer and that passes the "is_integral" test . On 10/15/07, David Abrahams <dave@boost-consulting.com> wrote:
The most obvious problem you have is that instantiating is_operator<BigInteger> is likely to cause an overloading ambiguity because BigInteger is derived from two different operator<T,U> specializations.
-- 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