Boost logo

Boost :

From: John Maddock (john_at_[hidden])
Date: 2007-09-24 05:19:34


Seweryn Habdank-Wojewódzki wrote:
> Dears
> // 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));
> }

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.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk