Reputation: 26983
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?
Upvotes: 3
Views: 4367
Reputation: 10165
Boost 1.47 and later support BOOST_STATIC_ASSERT_MSG
. Usage:
#include <boost/static_assert.hpp>
BOOST_STATIC_ASSERT_MSG(condition, msg)
If C++11 is available, or the compiler supports static_assert()
, the error message will be msg
string. Else the macro is treated as BOOST_STATIC_ASSERT(condition)
Upvotes: 0
Reputation: 99054
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::************)())'
Upvotes: 5
Reputation: 8155
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!")
Upvotes: 3