Boost logo

Boost :

Subject: Re: [boost] Boost.Fiber review January 6-15
From: Rob Stewart (robertstewart_at_[hidden])
Date: 2014-01-11 11:18:35

On Jan 11, 2014, at 11:01 AM, Nat Goodspeed <nat_at_[hidden]> wrote:

> On Fri, Jan 10, 2014 at 2:19 AM, Oliver Kowalke
> <oliver.kowalke_at_[hidden]> wrote:
>> 2014/1/9 Vicente J. Botet Escriba <vicente.botet_at_[hidden]>
>>> you can compare X and Y
>> You are surely right, but I don't see how? Could you show it?
>> implicit conversion to bool through operator bool()
> Vicente, the bad case is when class X and class Y provide operator bool. A coder inadvertently writes:
> if (myXinstance == myYinstance) ...
> (only of course with names in the problem domain rather than names that emphasize their respective classes). This should produce a compile error; you don't want X and Y to be comparable; the comparison
> is meaningless. Yet the compiler accepts it, converting each of
> myXinstance and myYinstance to bool and then comparing those bool values. The code runs. The product ships. Then some customer gets
> badly whacked...

That isn't an issue when the conversion operator is explicit, which Vicente suggested.

Boost list run by bdawes at, gregod at, cpdaniel at, john at