Re: Verify and expression
* Mark Van Peteghem:
Dave Harris schreef:
How about:
return VERIFY( p->value(), "bad value from: " << p->dump() );
where:
(a) p->value() should be evaluated exactly once regardless of
whether checks are enabled.
(b) The type and value returned should be the same as the type and
value of p->value(). (You can return 0 on failure, but it'd be
even better if that wasn't necessary.)
(c) p->value() may also use VERIFY.
(d) p->dump() may also use VERIFY.
(e) The code should be thread-safe.
(f) p->dump() is evaluated only if the check fails.
That's listed in my personal order of importance. (f) is the one I
would drop. The ideal VERIFY would satisfy them all.
If you want (a) and (b), I think it has to be done with a template
function
Yep.
[snip]
That means you should drop (f).
Nope, although the implementation would probably be simpler & possibly
(I'm not sure) also more efficient without that requirement.
But I don't see why (c) and (d) could be a
problem. These methods return before the template function is
entered.
I posted a reply to Dave Harris where I sketched a solution, but I hit
the "Send" button by mistake instead of saving a draft so it didn't
contain more than that sketch (and besides, it had lots of typos).
An actual C++ code version of that description is available at <url:
http://home.no.net/alfps/misc/verify.cpp>; compiles with MSVC and g++.
The code is incomplete in the sense that it doesn't support all
conceivable types, e.g., I haven't put in support for reference to
non-const expression. It's also incomplete in that I haven't added
threading support, which is somewhat system dependent; the places (two
of them) are marked with TODO comments. It's a proof-of-concept.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]