2010-07-13 18 views

回答

5

MPL有BOOST_MPL_ASSERT_MSG。例如。使用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::************)())' 
3

你有沒有嘗試過這樣的:

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

如果你的編譯器支持的C++ 0x static_assert,你可以做:

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

我試過,但我得到這個錯誤: 錯誤:「的sizeof」不完全型「的boost :: STATIC_ASSERTION_FAILURE 」 – lurscher 2010-07-13 21:56:56

+2

的無效申請@lurscher這是BOOST_STATIC_ASSERT總是給人消息。像喬治說的那樣使用BOOST_MPL_ASSERT_MSG – KitsuneYMG 2010-07-14 12:00:28

0

Boost 1.47 and later sup港口BOOST_STATIC_ASSERT_MSG。用法:

#include <boost/static_assert.hpp> 
BOOST_STATIC_ASSERT_MSG(condition, msg) 

如果C++ 11是可用的,或編譯器支持static_assert(),該錯誤消息將是msg字符串。否則宏被視爲BOOST_STATIC_ASSERT(condition)