C++ 用消息增强静态断言?

C++ 用消息增强静态断言?,c++,debugging,boost,metaprogramming,static-assert,C++,Debugging,Boost,Metaprogramming,Static Assert,在1.43 boost上,boost\u STATIC\u ASSERT似乎只允许输入一个布尔值,是否有其他方法允许我在编译错误上显示消息?MPL有。例如,使用GCC 4.2。为此: BOOST_MPL_ASSERT_MSG(false, THIS_DOESNT_WORK, (void)); 。。。结果: /path/to/file.cpp:42: error: no matching function for call to 'assertion_failed(mpl_::failed**

在1.43 boost上,boost\u STATIC\u ASSERT似乎只允许输入一个布尔值,是否有其他方法允许我在编译错误上显示消息?

MPL有。例如,使用GCC 4.2。为此:

BOOST_MPL_ASSERT_MSG(false, THIS_DOESNT_WORK, (void));
。。。结果:

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

你有没有试过这样的方法:

BOOST_STATIC_ASSERT(sizeof(long) == 64 && "Must have 64-bit long!")
如果编译器支持C++0x static_断言,则可以执行以下操作:

static_assert(sizeof(long) == 64, "Must have 64-bit long!")

Boost 1.47及更高版本的支持。用法:

#包括
BOOST\u STATIC\u ASSERT\u MSG(条件,MSG)

如果C++11可用,或者编译器支持
static\u assert()
,则错误消息将是
msg
string。否则宏将被视为
BOOST\u STATIC\u ASSERT(condition)

我尝试了此操作,但出现了以下错误:错误:对不完整类型“BOOST::STATIC\u ASSERTION\u FAILURE”应用“sizeof”无效@lurscher这是BOOST\u STATIC\u ASSERT总是给出的消息。使用BOOST\u MPL\u ASSERT\u MSG,就像Georg说的那样
#include <boost/static_assert.hpp>
BOOST_STATIC_ASSERT_MSG(condition, msg)