views:

60

answers:

2

Hi,

on 1.43 boost it seems that BOOST_STATIC_ASSERT just allows to put a boolean value, is there some alternative that allows me to display a message as well on the compile error?

+2  A: 

MPL has BOOST_MPL_ASSERT_MSG. E.g. using GCC 4.2. with this:

BOOST_MPL_ASSERT_MSG(false, THIS_DOESNT_WORK, (void));

... results in:

/path/to/file.cpp:42: error: no matching function for call to 
'assertion_failed(mpl_::failed************ (function()::THIS_DOESNT_WORK::************)())'
Georg Fritzsche
+1  A: 

Have you tried something like:

BOOST_STATIC_ASSERT(sizeof(long) == 64 && "Must have 64-bit long!")

If your compiler supports the C++0x static_assert, you can do:

static_assert(sizeof(long) == 64, "Must have 64-bit long!")
reece
i tried this but i got this error:error: invalid application of ‘sizeof’ to incomplete type ‘boost::STATIC_ASSERTION_FAILURE<false>’
lurscher
@lurscher That is the message that BOOST_STATIC_ASSERT always gives. Use BOOST_MPL_ASSERT_MSG like Georg says to
KitsuneYMG