From: Daniel Frey (daniel.frey_at_[hidden])
Date: 2003-03-12 12:01:51
Sam Partington wrote:
> No, I agree. You're right, much better to squint at error messages than to
> try and diagnose unexpected behaviour. Plus the messages I compared against
> were not all that bad to look at anyway, and all of them said something to
> the effect of "can't convert class 'A' to 'int' or something.
> > The VC issue bothers me, as I don't think I fully understand what
> > exactly happens. Doesn't the compiler give any additional messages to
> > explain
> > what exactly is ambiguous for operator&&? Does anyone know this
> > problem
> > and has a work-around?
> Unfortunately I don't understand this. It can go in the documentation,
> with the work around to be :
> if (!!a && ...)
> if (a)
> if (...)
Of course. But I was hoping for a work-around at the library-side, not
at the user's side. What exactly are the overloads that the VC thinks
might match? Or what type does it try to cast the expression to (instead
> Finally, if we choose this route, this means that we can take the approach
> of providing operator! and a private operator some_number_type() while the
> user provides operator bool. This is more semantically correct in my
> opinion, anyone have any problems with this?
> Oh, I should have patches posted very soon.
Fine. Remember that the name should probably change to reflect the
"corrected" semantics. Something like 'bool_negatable'?
But then, there is still some slight illogic here: We provide operator!,
but the protector is for operator bool. Two orthogonal concepts. Would
it make sense to separate them? If so, will 'bool_protector' have any
value? Those people not aware of the problem of providing operator
bool() will not use it, those that are aware will use Peter's
safe-bool-idiom when appropriate as it gives better error messages. And
where safe-bool is not applicable, you don't need a protector anyway
AFAICS. Hm... thoughts?
-- Daniel Frey aixigo AG - financial training, research and technology Schloß-Rahe-Straße 15, 52072 Aachen, Germany fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99 eMail: daniel.frey_at_[hidden], web: http://www.aixigo.de
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk