[Development] QOptional
Иван Комиссаров
abbapoh at gmail.com
Thu Aug 21 16:30:53 CEST 2014
Yes, it has both operator(T) and operator RestrictedBool
Still, i don't see a problem -
if (opt1 == false)
is equal to
if (opt1.operator==(false))
than expression is false.
If it is equal to
if (bool(opt1) == false)
than we have a problem. However, why the hell should compiler try to convert types if he has exact match for an operator to call?
Иван Комиссаров
21 авг. 2014 г., в 18:10, Thiago Macieira <thiago.macieira at intel.com> написал(а):
On Thursday 21 August 2014 11:34:17 Иван Комиссаров wrote:
> Иван Комиссаров
>
> 21 авг. 2014 г., в 2:10, Thiago Macieira <thiago.macieira at intel.com>
написал(а):
>>> The optional-cast-to-boolean is a source of problems for the current
>>> std::optional. That hasn't been solved.
>>>
>>> QOptional<bool> opt1 = false;
>>> QOptional<int> opt2 = 0;
>>> if (opt1)
>>>
>>> // this is true!
>>>
>>> if (opt2)
>>>
>>> // this is false!
>>
>> Hm, what? QOptional has no operator T and can't be converted to any value
>> (bool or not) directly.
>>
>> QOptional<bool> opt1 = false;
>> QOptional<int> opt2 = 0;
>> if (opt1)
>> // this is true!
>> if (*opt1)
>> // this is false!
>> if (opt2)
>> // this is true!
>> if (*opt2)
>> // this is false!
>
> Sorry, then:
>
> if (opt1 == false)
> // ?
> if (opt2 == false)
> // ?
>
> Does it have operator==(T)? Does it have operator RestrictedBool() / explicit
> operator bool()?
>
> Then there is a problem.
> --
More information about the Development
mailing list