Boost logo

Boost :

Subject: Re: [boost] [assert] Assert library? - Was: [regression] Where'sboost/assert.hpp ??
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2014-03-01 02:56:26

On Saturday 01 March 2014 02:43:35 Peter Dimov wrote:
> >> [1]
> >
> > 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__,

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.

Boost list run by bdawes at, gregod at, cpdaniel at, john at