Boost logo

Boost :

From: John Torjo (john_at_[hidden])
Date: 2003-05-08 01:15:30


Hi Pavel,

> Hello John,
>
> Whoa, its getting big! I need to grok it fully but here are few comments:

Thanks ;-)

>
> >13. Multiple levels of assertion.
> >There might be several levels of assertion.
> >
> I think this would make things too complicated. I use asserts a lot and
> since it is so easy it doesn't take time or doesn't interrupt flow to
think
> over details.

True. But if you use normal syntax, you don't have to worry at all about
this.
I provided it because it doesn't interrupt normal flow. If you want to add
(a different) level to an assert, do something like this:

// before
BOOST_ASSERT( i > 1000)(i);

change to:
//
BOOST_ASSERT( i > 1000)(i)
  .level( fatal_error, "value too big!");

I think this is pretty straightforward.

>
> IMHO the best would be to keep assert() syntax more less as is and allow
use
> features transparently.

Hope I'm doing so ;-)

>
> >For Win32, I will show a message box, for other platforms, output to cout
> >and read from cin.
> >
> Some apps using graphics libraries like Qt may recognize them and use
their
> dialog boxes automatically. I'll look how it is with vxWindows.

Please, let me know. I'm really interested!

>
>
> >BOOST_ENFORCE allows for enforcing a condition on a value. If that fails
> >(usually) an error will be thrown.
> >
> I have one idea: I often write code like:
>
> void foo() {
> int* x = get_something(); // cannot fail
> if (x == 0) {
> assert(false);
> return;
> }
> ...
> }
>
> It is check of some highly improbable situation which I want to handle
> locally, not via exception (if I have 100 possible errors like this each
on
> 100 places).
>
> I wonder it something like this would be possible:
> void foo() {
> int* x = ENFORCE_ASSERT(get_something());
> // equivalent to:
> // int* x = get_something();
> // if (!x) { assert(false); return; }

TRUE!!!
I could allow for BOOST_VERIFY - something like the MFC's VERIFY.
And, I will have to allow for some syntax to be able to return something
from the function.

For instance:

int get_handle( const char * str)
{
    BOOST_VERIFY( str != NULL)(str) return 0;
    ...
}

I'll have to think of a syntax that will work.

Best,
John


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