Boost logo

Boost :

Subject: Re: [boost] [assert] static_assert envy
From: Robert Kawulak (robert.kawulak_at_[hidden])
Date: 2011-01-18 12:47:57

2011/1/18 Steven Watanabe <watanabesj_at_[hidden]>:
> What exactly is wrong with
> BOOST_ASSERT( !foo() || assertion )
> or
> BOOST_ASSERT( foo() ? assertion : true )
> IMHO, the last thing we need is lots of
> minor variations that don't add any
> real utility.

The utility here is communicativeness. Upon seeing:

BOOST_ASSERT( !"we shouldn't get there" );
BOOST_ASSERT( condition && "this shouldn't happen" );
BOOST_ASSERT( !foo() || condition && "something is wrong" );

you have to turn your mind into a Karnaugh table for a while if you
want to understand what this code does. OTOH:

BOOST_FAIL_MSG( "we shouldn't get there" );
BOOST_ASSERT_MSG( condition, "this shouldn't happen" );
BOOST_ASSERT_IF_MSG( foo(), condition, "something is wrong" );

communicates the author's intention in a direct way and also makes it
harder to make mistakes in the boolean expressions (note that foo and
condition above may be boolean expressions themselves making the first
technique quite error-prone).

You could equally well ask what is the real utility of having
C++-style casts over the C-style one. ;-)

Best regards,

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