|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2004-01-23 18:10:22
"Rozental, Gennadiy" <gennadiy.rozental_at_[hidden]> writes:
>> It causes lots of recompilation; that's really frustrating
>> when the test could be done just as well if not better at
>> compile-time using some kind of static assert.
>
> Do you have any specific compile time test tools in mind? Does it worth
> reusing?
# include <boost/type.hpp>
# include <boost/static_assert.hpp>
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
template <bool>
struct assert_apply_base;
template <>
struct assert_apply_base<true>
{
enum { value = 1 };
};
template <class E>
struct assert_apply : assert_apply_base<E::value> {};
#else
# include <boost/mpl/if.hpp>
# include <boost/mpl/bool.hpp>
# include <boost/type_traits/is_same.hpp>
template <E>
struct assert_apply
: boost::mpl::if_<E,boost::mpl::true_,void>::type
{};
#endif
#define ASSERT_APPLY( E ) \
enum { BOOST_JOIN(boost_static_assert_enum_, __LINE__) \
= assert_apply<E>::value }
// ----------
#include <boost/mpl/not.hpp>
ASSERT_APPLY(is_class<Foo>);
ASSERT_APPLY(mpl::not_<is_class<int> >);
// etc.
-- Dave Abrahams Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk