Boost logo

Boost :

Subject: Re: [boost] [signals2] Test failure in C++11 (trivial fix for incorrect usage of boost::optional)
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2014-02-28 11:31:52


On Fri, Feb 28, 2014 at 7:38 PM, Frank Mori Hess <fmh6jj_at_[hidden]> wrote:
> On Thu, Feb 27, 2014 at 8:45 PM, Gavin Lambert <gavinl_at_[hidden]> wrote:
>> On 28/02/2014 12:33, Quoth Frank Mori Hess:
>>>
>>> Ah, I wasn't aware optional already had overloaded the comparison
>>> operators with comparisons of optional<T> vs T. A little unfortunate
>>> IMO, it makes optional<bool> a bit of a disaster when any sort of
>>> conversion to bool at all is supported.
>>
>>
>> Not really; tristate bool logic with optional<bool> is pretty
>> straightforward. It usually falls into the pattern:
>>
>> if (value == true) {
>> /* do something when true */
>> } else if (value == false) {
>> /* do something when false */
>> } else {
>> /* do something when null/none/unknown/unspecified */
>> }
>>
>> There is a little trap for the unwary where:
>>
>> if (value) {
>> /* either true or false */
>> } else {
>> /* only null, not false */
>> }
>>
>> But once you get used to it, I'd hardly call it a "disaster".
>
> Nothing is a problem once you get used to it. I apologize for using a
> bit of hyperbole, let me try again. I consider the following obvious:
> given two expressions like "!x" and "x==false" we have:
>
> desirable behavior: they both compile and mean the same thing.

I don't think I agree with that. IMO, "x==false" should not compile
since it has ambiguous interpretation.

> neutral behavior: only one compiles.

This one is desirable for me.

> undesirable behavior: they both compile and mean completely different things.


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