[Development] QOptional
Simon Hausmann
simon.hausmann at digia.com
Thu Aug 21 11:25:31 CEST 2014
On Thursday 21. August 2014 13.13.15 Иван Комиссаров wrote:
> Of course, i can:)
>
> bool ok;
> const int value = string.toInt(&ok);
> if (ok)
> qDebug() << "value is" << value;
>
> // ====
> const auto value = string.toInt();
> if (value)
> qDebug() << "value is" << *value;
To be honest: I find the "bool ok" variant much easier to read.
"if (value)" on an auto variable can mean so many things. In the
above example you could very easily think: Ah, toInt returns an int,
so the type of "value" is probably int, so if (value) checks if it's non-zero.
I don't think that makes for a very intuitive API. Yes, it's less to type, but
less isn't always more :)
Simon
More information about the Development
mailing list