RE: [boost] Re: Standard C Library and C++ / BOOST

Vladimir Prus wrote:
John Torjo wrote:
I really wish there were exception-throwing versions -- since that code is boring and still contains a couple of error-handling problems. However, most of the functions above are acutally from POSIX, not from standard C, so I'm not sure how much wrapped C functions would help me.
Unless I'm mistaken, you're talking something similar to Andrei Alexandrescu's ENFORCE: http://www.cuj.com/documents/s=8250/cujcexp2106alexandr/
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. 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. Regards, Reece _________________________________________________________________ Express yourself with cool new emoticons http://www.msn.co.uk/specials/myemo

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
participants (2)
-
Reece Dunn
-
Vladimir Prus