Boost logo

Boost :

From: Craig Henderson (cdm.henderson_at_[hidden])
Date: 2002-09-08 12:23:28


I have a problem with the BOOST_STATIC_ASSERT macros on VC++.Net. My class
has a default template parameter that must be a container with a specific
value type. In the definition of the class, I am trying to use
BOOST_STATIC_ASSERT to enforce this condition, however the code fails to
compile with these errors:

warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance
warning)
        c:\Development\X\X.hpp(264) : see reference to class template
instantiation 'boost::X<T,Res>' being compiled
error C2975: 'x' : invalid template argument for
'boost::STATIC_ASSERTION_FAILURE', constant expression expected
        c:\Development\Library\Boost\Current\boost\static_assert.hpp(29) :
see declaration of 'x'
error C2027: use of undefined type 'boost::STATIC_ASSERTION_FAILURE<x>'
        with
        [
            x=false
        ]

A snippet of the code follows:

template<typename T>
class X_result : boost::noncopyable
{
...
}:

template<typename T, typename Res=std::list<X_result<T> *> >
class X : boost::noncopyable
{
  public:
    // define a typedef for the results
    typedef Res result_set;
    BOOST_STATIC_ASSERT(typeid(Res::value_type)==typeid(diff_result<T> *));

...
};

However, outputing these typeids at runtime yields identical ids:

std::cout << typeid(Res::value_type).name() << std::endl
    << typeid(diff_result<T> *).name() << std::endl
    << "Equality==" << (typeid(Res::value_type) == typeid(diff_result<T>
*));

outputs this:
class boost::diff_result<class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > > *
class boost::diff_result<class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > > *
Equality==1

Please could someone explain this behaviour? Am I missing something or there
something wrong with the macro or vc++ compatibility?

Regards
-- Craig


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