Boost logo

Boost :

From: Fernando Cacciola (fernando_cacciola_at_[hidden])
Date: 2006-10-23 14:33:34


Richard Smith wrote:
> I was recently bitten by bug in some code using
> boost::optional. A simple test case is:
>
> #include <boost/optional.hpp>
> #include <cassert>
>
> int main() {
> boost::optional<int> i = 0;
> assert( i == 0 );
> }
>
> Somebody had written code like this, presumably assuming the
> second argument to the comparison operator would convert
> implicitly to a boost::optional<int> and the code would
> behave as if it read:
>
> assert( i && i.get() == 0 );
>
OK, deep comparison operators have been requested before, but all this
time I remained unconvinced there were really needed, until now.

As you said, optional<> provides value-based semantics in other places,
so given the kind of bug you discovered, I think is time to add these too.

Best

Fernando Cacciola


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