[type_traits] Interesting problem with is_base_of.

Dears There are two codes. The first is workig as it is specified in the documentation, but the second not. Why there are problems with the second code? Regards. // This code works perfectly #include <boost/type_traits.hpp> #include <boost/static_assert.hpp> #include <boost/utility.hpp> template <typename B, typename R> class test { public: test () { BOOST_STATIC_ASSERT((boost::is_base_of<B, R>::value)); } }; int main() { test <int, int> t (); } // The code belo is not working #include <boost/type_traits.hpp> #include <boost/static_assert.hpp> #include <boost/utility.hpp> template <typename B> class test { public: template <typename R> test (R const &) { BOOST_STATIC_ASSERT((boost::is_base_of<B, R>::value)); } }; int main() { test <int> t (static_cast<int>(0)); } -- |\/\/| Seweryn Habdank-Wojewódzki \/\/

Seweryn Habdank-Wojewódzki wrote:
I'm not sure if it's clear from the docs, but the behaviour of is_base_of was changed in the draft std so that it evaluates to true for any is_base_of<T,T>. So if you want to assert that B really is a base class of R, then use: is_base_of<B,R>::value && !is_same<B,R> or is_base_of<B,R>::value && is_class<B>::value Ah, just checked the docs, and it does say: " Note that is_base_of<X,X> will always inherit from true_type. This is the case even if X is not a class type. This is a change in behaviour from Boost-1.33 in order to track the Technical Report on C++ Library Extensions." HTH, John.

Hi Thanks for the reply.
No. This is not clear :-).
I know that solution, but the more important is that there is difference between that two cases. Theoretically both codes have to generate the same result. Because they are working on the same types. There have to be no difference in the assertions -- failed or not, but assertions have to be the same.
Yes. That was the base of the question.
This is a change in behaviour from Boost-1.33 in order to track the Technical Report on C++ Library Extensions."
OK. Thanks. Best regards. -- |\/\/| Seweryn Habdank-Wojewódzki \/\/
participants (2)
-
John Maddock
-
Seweryn Habdank-Wojewódzki