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;
}


Consider:

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


"Kevin S. Van Horn" <[EMAIL PROTECTED]> wrote in message
news:Pine.LNX.4.44.0211110833530.25298-100000@;speech.cs.ndsu.nodak.edu...
> 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?
>





_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to