Boost logo

Boost :

From: John Torjo (john.lists_at_[hidden])
Date: 2004-01-12 01:48:46


Dan W. wrote:

> Allright, just for the record, this is where it stands at right now:
>
> ---------------------------------------------------------
> //file: ensure.hpp
> #ifndef ENSURE_HPP
> #define ENSURE_HPP
>
> #ifdef _DEBUG
> # define ENSURE(x) do{if(!((x)))asm int 3;}while(0)
> #else
> # define ENSURE(x) (void)(0)
> #endif
>
> #endif
> ---------------------------------------------------------
> //test ensure...
> #include "ensure.hpp"
> #include <cassert> //last-time included, ever
>
> int main()
> {
> int i = 2;
> ENSURE( i == 2 );
> //assert( i != 2 ); //un-comment to feel the pain
> ENSURE( i != 2 );
> return 0;
> }
> ---------------------------------------------------------
>
> I dare anyone to actually try it, and *then* tell me that it's no better
> than assert()...
>

Dan, I dare you to try this:

// assert_example.cpp
#include <boost/smart_assert_ext.hpp>

void login_admin( const std::string & username, const std::string & passw) {
     SMART_ASSERT( username == "admin" && passw == "secret")
(username)(passw)
         .msg( "Unauthorized administrator login!");
}

int main() {
     login_admin( "admin", "anonymous");
     return 0;
}

You can get the code from http://www.torjo.com/smart_assert.zip
Also, it's been quite tested on VC6.

Best,
John


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