From: Douglas Gregor (gregod_at_[hidden])
Date: 2001-09-20 14:57:55
On Thursday 20 September 2001 03:35, you wrote:
> The conversion to bool allowed by safe_bool might allow the following:
> optional<bool> foo();
> void bar()
> bool b = foo() ;
> // this will compile OK, but it is an error because the value of 'b'
> won't be the bool value
> // contained in the result of 'foo' -which is what the user would
> expect- // but the boolean condition corresponding to the initialized state
> of foo's result.
Ah yes, good point.
> I like the above.
> I just realized that I don't want optional<T> to be bool convertible. I
> want it to allow *only* something like if ( opt ), but that seems to
> require a bool conversion, even a very restricted one.
It's a pity we can't overload operator "if" :)
I think your ! and !! method is probably the only recourse for optional<bool>
to avoid user confusion.
Boost list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk