Boost logo

Boost :

From: Darren Cook (darren_at_[hidden])
Date: 2004-01-05 19:31:43


>> Anyway I remember that John Torjo already posted similar library (named
>> smart_assert) to boost.
>
> I don't mean this as a criticism of smart_assert (more of a
> self-criticism): I'm lazy, and I got exhausted and lost trying to learn
> how to use it, and all those chains of parenthesisized statements give
> me shivers. I just want something simple and lightweight for myself.
> And for logging errors to a file, I'd rather have some LOGERR().

All the "smart" stuff in smart assert is optional. Here is the smart assert
version of your earlier example:

----------------------------------------------------
#include <boost/smart_assert_ext.hpp>

char first_char( char const * s ) {
SMART_ASSERT( s && ::strlen(s) );
return s[0];
}

int main(int,char**){
using namespace boost::smart_assert;
assert_settings().set_level_handler(lvl_debug, &debug_on_assert);
char c=first_char("");
}
----------------------------------------------------

You could edit default_handle_debug() in
boost/smart_assert/priv/fwd/smart_assert_h_basic.hpp to save having to call
set_level_handler in every program.

Unfortunately there is no debug_on_assert() function :-). This should do it
(if included after smart_assert_ext.hpp).

namespace boost {

namespace smart_assert {

void debug_on_assert( const assert_context &) {
break_into_debugger();
}

}
}

I've not tested it, but now I think about it the debugger will not break on
the line of the assert but in the above debug_on_assert() function. So not
quite what you want.

Darren


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