From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2001-09-18 08:20:50
----- Original Message -----
From: Douglas Gregor <gregod_at_[hidden]>
Sent: Monday, September 17, 2001 4:57 PM
Subject: Re: [boost] Re: More on the optional class.
> On Monday 17 September 2001 11:35, you wrote:
> > With respect to the 'operator T*()', I haven't adopted it becuase it
> > allow the following:
> > optional<int> opt1 = 1234 ;
> > optional<int> opt2 = 1234 ;
> > if ( opt1 == opt2) // this will compile OK if there is an 'operator
> > T*()', but won't evaluate as expected.
> > the above boolean expression is ill-formed w.r.t the optional
> > specification, but there is no compile-time nor runtime indication of
> You can "poison" comparisons between optional<T>'s very easily, however,
> template<typename T1, typename T2>
> void operator==(const optional<T1>&, const optional<T>&);
> Since the operator == returns void, any attempt to use "opt1 == opt2" will
> generate a compile-time error. In the pointless case that the user writes
> (harmless) statement expression "opt1==opt2;", the failure will occur at
Great technique! I love to learn a new nice trick to makes things easier!
> > I decided to support only those idioms that would prevent the mistakes
> > above. AFAICT, these are (1) operator !(), (2) a friend 'T* get(opt)'
> > function (thanks to Peter Dimov!).
> Many of these concerns (how to use an object in a boolean context) were
> discussed prior to the review of Function. I settled on the use of Peter
> Dimov's pointer-to-member-of-useless-class technique for the boolean
> conversion, and on poisoning operator== and operator!= for Function class
> templates. The source file boost/function/function_base.hpp contains the
> for both.
Good. I'll look at it...
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk