ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> boost
boost
[boost] Re: Proposed Boost Assert -- once again
by Eric Woodruff other posts by this author
Nov 11 2002 4:55PM messages near this date
Re: [boost] Proposed Boost Assert -- once again | RE: [boost] 'function' idea
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" <Kevin.VanHorn@[...].edu>  wrote in message
news:Pine.LNX.4.44.0211110833530.25298-100000@[...]..
>  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
Thread:
Kevin S. Van Horn
Peter Dimov
Bertolt Mildner
Peter Dimov
Fernando Cacciola
Peter Dimov
Rob Stewart
Fernando Cacciola
Fernando Cacciola
David Abrahams
Peter Dimov
Vladimir Prus
Peter Dimov
Eric Woodruff

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved