Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2007-08-21 13:51:04


on Tue Aug 21 2007, Martin Apel <martin.apel-AT-simpack.de> wrote:

> Hughes, James wrote:
>> Hello all,
>>
>> I want some template code to assert if the passed in template type is
>> NOT derived from a particular base class.
>>
>> I've looked through the Template Metaprogamming book, but haven't seen
>> anything that can do this, but I seem to remember something along those
>> lines.
>>
>> Can anyone help?
>>
>> James
>>
>>
> Hi James,
>
> the easiest way is something like the following:
>
> #include <boost/type_traits.hpp>
> #include <boost/static_assert.hpp>
>
> BOOST_STATIC_ASSERT (boost::is_base_of<Base, Derived>::value);

  BOOST_MPL_ASSERT((boost::is_base_of<Base,Derived>))

Don't use BOOST_STATIC_ASSERT if you can help it. It gives far
inferior results when assertions fail.

-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com
The Astoria Seminar ==> http://www.astoriaseminar.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net