Boost logo

Boost :

From: Martin Bonner (Martin.Bonner_at_[hidden])
Date: 2007-10-29 11:49:07


From: Roland Schwarz

> Library authors often use the pattern:
>
> void foo(void)
> {
> unsigned res = SomeFuncWithSideEffects();
> BOOST_ASSERT(res);
> }
>
> This causes a lot of noise on some compilers (e.g. gcc)
> about unused variables when building in release mode.
>
> I suggest a macro
>
> void foo(void)
> {
> BOOST_ASSERT_DEF( unsigned res = ) SomeFuncWithSideEffects();
> BOOST_ASSERT(res);
> }

MFC had (has) a VERIFY macro for this. If we introduced a BOOST_VERIFY,
the usage would look like:
void foo(void)
{
        BOOST_VERIFY( SomeFuncWithSideEffects() );
}

Implementation would be (something like):

#if defined(NDEBUG)
# define BOOST_VERIFY( expression ) expression
#else
# define BOOST_VERIFY( expression ) bool b = expression;
BOOST_ASSERT(b)
#endif

(Yes, I know; real code would need to invent a unique name that wouldn't
clash, or introduce a scope, or something, but you get the idea.)

-- 
Martin Bonner
Senior Software Engineer/Team Leader
PI SHURLOK LTD
Telephone: +44 1223 441434 / 203894 (direct)
Fax: +44 1223 203999
Email: martin.bonner_at_[hidden]
www.pi-shurlok.com
disclaimer

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk