Boost logo

Boost :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2004-03-30 00:46:07


Reece Dunn wrote:

>>Yes, you're right. However, there's one additional wish -- I'd like an
>>appraoch different macroses for different functions. E.g. for POSIX calls
>>I only encounter -1 returns and NULL returns for error reporting. So I'd
>>like
>
>> int tty = check(open(check(ctermid(0)), O_RDRW);
>
>>to work. I guess this could be done by providing two overloads for the
>>'Wrong' function...., but not, the 'Enforcer' template only works for
>>specific type of return value :-(
>
> My errorcheck class (see other posts) has an error policy where you can
> change the fail test. The default is to test errorcode < 0.

The code you've posted had the check hardcoded, maybe I've missed some other
post?

> A current weakness is that it does not return the value passed to it on
> assignment, so you cannot use exactly like the above example. I have been
> updating it to support errno handling, but this (at present) requires
> something like:
>
> boost::errorcheck< ... > check;
>
> FILE * fp = ::fopen( 0, "r" );
> check( fp != 0 ); // assert-like syntax
> ::fclose( fp );
>
> If you are interested, I'll work on supporting constructs like your
> example above.

I actually wonder if we need a class. Does it have any advantages over
function? E.g:

     template<class Checked = default_checker, class T = void>
     T check(T t)
     {
        if (Checker(t))
                throw ...
        return t;
     }

- Volodya


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