boost static assert and is_base_of question.
Hi, how would I ensured that class U of template class is a dervied class of boost::operators<U> using BOOST_STATIC_ASSERT and boost::is_base_of... template <T> myFunc(const T& a) { typedef boost::operators<T> operatorT; BOOST_STATIC_ASSERT(is_integral<T>::value || is_base_of<operatorT, T>::value); // ... other codes. } doing this gives me an error. arguments, but takes just 1 ./cs512/c++/cppdef/DiffieHellman.cpp: In function `T boost::random_prime(boost:: function<bool ()(const T&, const T&), std::allocator<void> >, int)': ./cs512/c++/cppdef/DiffieHellman.cpp:23: error: `BOOST_STATIC_ASSERT' was not de clared in this scope ./cs512/c++/cppdef/DiffieHellman.cpp:49:78: macro "BOOST_STATIC_ASSERT" passed 2 arguments, but takes just 1 ./cs512/c++/cppdef/DiffieHellman.cpp: In function `boost::tuples::tuple<T, T, bo ost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boos t::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost: :tuples::null_type, boost::tuples::null_type> boost::dh_init(const boost::any&)' : ./cs512/c++/cppdef/DiffieHellman.cpp:49: error: `BOOST_STATIC_ASSERT' was not de clared in this scope ./cs512/c++/cppdef/DiffieHellman.cpp:64:78: macro "BOOST_STATIC_ASSERT" passed 2 arguments, but takes just 1 ./cs512/c++/cppdef/DiffieHellman.cpp: In function `T boost::dh_secret(const T&, const T&, const T&)': ./cs512/c++/cppdef/DiffieHellman.cpp:64: error: `BOOST_STATIC_ASSERT' was not de clared in this scope make[1]: *** [lib/DiffieHellman.o] Error 1 make[1]: Leaving directory `/c/CPW/cs_classes' make: *** [all-before] Error 2
chun ping wang wrote:
Hi, how would I ensured that class U of template class is a dervied class of boost::operators<U> using BOOST_STATIC_ASSERT and boost::is_base_of...
template <T> myFunc(const T& a) { typedef boost::operators<T> operatorT; BOOST_STATIC_ASSERT(is_integral<T>::value || is_base_of<operatorT,
value); // ... other codes. }
doing this gives me an error.
Right, since BOOST_STATIC_ASSERT is a macro, you need some extra parenthesis to stop the "," in the template arg list to is_base_of from being seen as a macro-argument separator: BOOST_STATIC_ASSERT((is_base_of<A, B>::value)); HTH, John.
participants (2)
-
chun ping wang
-
John Maddock