Boost logo

Boost :

From: Andy Glew (glew_at_[hidden])
Date: 1999-08-30 13:09:49


> Do others think that some such template base assertion approach is
> worth developing for boost? Has anyone else tried to develop
> assert() replacements?

> assertion( i < 1 ); // always check
> assertion<DEBUG_ONLY>( i < 2 );

Oh, as I meant to add:

This is a good idea: specifying assert code activation at the point of use.
As I mentioned earlier, I use
        assert() / no_assert() / always_assert()

The difference is of emphasis. So many people are wired into the
model "assert() is normally disabled" that you will surprise folks
if the default assertion is enabled.

Similarly, I think that we want to encourage assertions, so making
the "fast compile" version more verbose is counterproductive.
I think that Stroustrup/Koenig's assertion objects may be better
here.

Similarly, there is a significant likelihood that a luser will put side
effects in an assertion:

    assert( i-- )

i.e. that the program will not work if the assertions are disabled.

Thus, I find it useful to have a way of globally disabling all assertions,
to maximize the chance of detecting such lossage.

---
A friend of mine at Apple goes further:  he defines an assertion that
can be used in expressions. If you will pardon the C-ism, a contrived example:
    char* ptr_plus_1 = EXPECT( != 0, malloc(size+1) ) + 1;

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