Boost logo

Boost :

From: Anthony Williams (anthony.williamsNOSPAM_at_[hidden])
Date: 2002-10-17 09:41:16


Peter Dimov writes:
> From: "Anthony Williams" <anthony.williamsNOSPAM_at_[hidden]>
> > Peter Dimov writes:
> > > This means that the requirements are broken, not that there is
> something
> > > wrong with the code. The requirement should be "usable in boolean
> > > expressions and other contexts where a bool is required" and not
> > > "convertible to bool". I'm sure that this is the original intent.
> >
> > How does this differ from "must be bool"?
>
> It doesn't because I wasn't precise. By "other contexts..." I meant if(x),
> while(x), x? ...: ..., !x, and so on, and obviously not
>
> bool & r(x);
>
> or
>
> struct V { V(bool); };
> void f(V);
>
> f(x);
 
If (i1!=i2) yields an expression convertible to bool, but not bool, then you
have to guard against, for example,

template<typename T,typename U>
MyRandomReturnValue operator&&(T lhs,U rhs);

(in an appropriate namespace) hijacking your boolean expression. This requires
that you either cast the subexpressions to bool explicitly, or that these
"convertible to bool" types are builtin types, in which case they might as
well be bool --- I can't see much benefit in operator!= returning a void*, for
example.

> > If the real intent did not make it into the precise wording of the
> standard,
> > this is a bug in the standard (a DR) rather than an example of de-facto
> > requirements that are more important than the specified requirements.
>
> It's both. These aren't mutually exclusive.

In which case, write it up and get an issue number ;-)

Anthony

-- 
Anthony Williams
Senior Software Engineer, Beran Instruments Ltd.
Remove NOSPAM when replying, for timely response.

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