
On Saturday 01 March 2014 02:43:35 Peter Dimov wrote:
[1] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3877.pdf
Assertion macros taking a level (BOOST_ASSERTL, BOOST_ASSERTL_MSG) controlled by, f.ex. BOOST_ASSERT_LEVEL (0 - opt, 1 - debug, 2 - safe) would be a relatively straightforward addition.
The N3877 approach of supplying three separate macros, one per level, has one advantage though - it doesn't generate "condition is always true/false" warnings.
Assume for instance that BOOST_ASSERTL(expr, level) is
((level) <= BOOST_ASSERT_LEVEL? BOOST_ASSERT(expr): (void)0)
Here level <= BOOST_ASSERT_LEVEL will almost always be a constant expression, hence warnings.
Leaving the note about usefulness of this warning aside, you could work around it e.g. by using preprocessor tricks: #define BOOST_ASSERTL(expr, level)\ BOOST_ASSERTL_ ## level(expr) or template specialization: #define BOOST_ASSERTL(expr, level)\ assert_impl< (level) <= BOOST_ASSERT_LEVEL >::do((expr), #expr, __FILE__, __LINE__) Of course, this would only work for compile time constant levels. The three- macros approach guarantees that so it might cause less surprises than the level-as-argument approach.