Boost logo

Boost :

From: Darren Cook (darren_at_[hidden])
Date: 2003-05-08 03:54:36


>>BOOST_ASSERT(some_lenghty_function())(???)
>
> 2. BOOST_ASSERT( some_lengthy_function() > 10) ( some_lengthy_function());
> Indeed, is kind of lengthy, but this is life :-(
> The point is that I could provide the v_ macro as well - it would not be too
> complicated. What do others think?

I wondered about this as well. Here is one option:
   BOOST_PREPARE_ASSERT(int _result=some_lengthy_function());
   BOOST_ASSERT(_result>10)(_result);

I've used something like this in my own assert library, but have never been
happy with having a local variable that is only there in debug mode.

How would the v_ macro work?

>>If not-idempotent function is given as parameter, it may have sideeffects
>>(silly contrived example: pool resource allocator which gets exhausted in
>>the middle of assert).
>
> I did think (a lot!) about this. But, it's reasonable to assume that
> functions/ member functions that are called within an ASSERT should all be
> constant, because they won't be called at all in release mode.

I'm not convinced that is reasonable, but even if no side effects the assert
might take a significant amount of time (e.g. checking an object matches
what is in a back-end database, or checking a graph has no cycles).

Darren


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