Boost logo

Boost :

From: Eric Woodruff (Eric.Woodruff_at_[hidden])
Date: 2002-11-11 11:55:36

I've always used the examples out of TC++PL of some assertions:

template <typename Exception>
assertion (bool const condition) {
     if (!condition) {
        throw Exception ();

template <typename Exception>
assertion (bool const condition, Exception const& exception) {
    if (!condition) {
        throw exception;

What about having a function-class based assertion that worked like:

assertion (!Sanity::invalidArgument || 0 != p, Throw (invalid_argument
("must not be zero")));

assertion (2 > x, Abort ());

or maybe even

assertion (2 > x, DontCompile ());

---- implementation ---

template <typename Function>
assertion (bool const condition, Function const& f) {
    if (!condition) {
        f ();

It looks very idiomatic to me.

I've also found things like this useful:

template <typename Condition, typename Exception>
Condition const& assertNonZero (Condition const& condition) {
    if (0 == condition) {
        throw Exception ();

    return condition;


return x / assertNonZero<range_error> (b - a);

"Kevin S. Van Horn" <Kevin.VanHorn_at_[hidden]> wrote in message
> It's been six days since I posted this, without a single response, so I'm
> going to try again. Based on earlier discussions, I thought there might
> be some interest in this. Does anyone have any problems with the proposed
> interface? Should I turn this into a formal proposal for submission to
> Boost? Peter, how does this compare with the changes to
> <boost/assert.hpp> you were planning to do / are doing?

Boost list run by bdawes at, gregod at, cpdaniel at, john at