As I recall BOOST_MPL_ASSERT was once preferred. Is this still true? Anyone know why?
As I recall BOOST_MPL_ASSERT was once preferred. Is this still true? Anyone know why?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
[Answering my own question]
It depends. This is an apples to oranges comparison. Although similar, these macros are NOT interchangeable. Here’s a summary of how each works:
BOOST_STATIC_ASSERT( P )generates a compilation error ifP != true.BOOST_MPL_ASSERT(( P ))generates a compilation error ifP::type::value != true.The latter form, despite requiring double parentheses, is especially useful because it can generate more informative error messages if one uses Boolean nullary Metafunctions from Boost.MPL or TR1’s
<type_traits>as predicates.Here is an example program that demonstrates how to use (and misuse) these macros:
For comparison, here are the error messages my compiler (Microsoft Visual C++ 2008) generated for lines 19 and 21 above:
So if you’re using metafunctions (as defined here) as predicates then
BOOST_MPL_ASSERTis both less verbose to code and more informative when it asserts.For simple boolean predicates,
BOOST_STATIC_ASSERTis less verbose to code although its error messages may be less clear (depending on your compiler.)