Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-11-12 08:19:41


See the code at the end for my proposed implementation of BOOST_ASSERT.

Design goals:

* Simple;
* Off by default;
* User customizable.

Modes of operation include:

1. off; when BOOST_DEBUG is not defined.
2. simply use assert(); with -DBOOST_DEBUG and -DBOOST_ASSERT=assert.
3. invoke user error handler (boost_error), then assert();
with -DBOOST_DEBUG.
3a. log error and throw.
3b. log error and continue.
3c. log error and assert().
3d. log error and terminate (whole process or current thread only.)
3e. perform cleanup and assert().

etc.

Comments?

--
Peter Dimov
Multi Media Ltd.
#define BOOST_DEBUG
// boost/assert.hpp
#ifdef BOOST_DEBUG
#include <assert.h>
#endif
#ifndef BOOST_ASSERT
#ifdef BOOST_DEBUG
bool boost_error(char const * expr, char const * file, long line);
#ifndef BOOST_ERROR
#define BOOST_ERROR(expr) (expr || !boost_error(#expr, __FILE__, __LINE__))
#endif
#define BOOST_ASSERT(expr) assert(BOOST_ERROR(expr))
#else
#define BOOST_ASSERT ((void)0)
#endif
#endif
//
// user error handler
#include <cstdio>
bool boost_error(char const * expr, char const * file, long line)
{
 std::printf("boost_error(%s, %s, %ld)\n", expr, file, line);
 return true;
}
//
// boost or user code
int main()
{
 BOOST_ASSERT(0 == 1);
}

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