Boost logo

Boost :

Subject: Re: [boost] [assert] static_assert envy
From: Robert Kawulak (robert.kawulak_at_[hidden])
Date: 2011-01-18 14:03:43


2011/1/18 Thomas Klimpel <Thomas.Klimpel_at_[hidden]>:
>> BOOST_FAIL_MSG( "we shouldn't get there" );
>
> I would prefer
> BOOST_ASSERT_MSG( false, "we shouldn't get there" );
> so I don't need to think about the details of the differences between BOOST_FAIL_MSG and BOOST_ASSERT.

It is a matter of taste, I'd rather use BOOST_FAIL_MSG here as more
direct. As I said, I've been using .NET's Debug.Fail along
Debug.Assert and I find it quite useful. It can also make the final
message look a bit nicer – not something of big importance, but
always.

>> BOOST_ASSERT_IF_MSG( foo(), condition, "something is wrong" );
>
> I would prefer
> BOOST_ASSERT_MSG( !foo() || condition, "something is wrong" );
> so I don't need to think about the details of the differences between BOOST_ASSERT_IF_MSG and BOOST_ASSERT.

Then consider a simple example:
foo is: !c1.empty() && !c2.empty()
condition is: c1.front() ? c2.front() : def_val()

Now you have to compute !foo || condition, which is simple, but: 1)
makes several opportunities for a mistake, 2) results in an expression
that may be harder to decipher than the two initial expressions. And
again, the resulting assert message can be nicer, too.

We wouldn't be asking for those constructs if we weren't kept finding
ourselves in situations where they would be indeed good to have.

Best regards,
RK


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