[Development] QOptional

Иван Комиссаров abbapoh at gmail.com
Wed Aug 20 20:04:24 CEST 2014


Hello!

I've started working on a QOptional class (https://codereview.qt-project.org/#/c/92006/).

As Thiago mentioned in gerrit, there are some things to discuss.

First is a QVariant integration. I think, i should add:
1) template<typename T> QVariant::QVariant(const QOptional<T> &o); constructor
2) template<typename T> QOptional<T> QVariant::toOptional() const; method (like value<T>())

Right now, QOptional has isNull() method that indicates that optional object has no value. I suggest to rename this method to isValid() and add new isNull() method that checks if optional contains default-constructed value. This will make it more consistent with QVariant API.

So, the i vote for following behaviour;
Invalid QVariant (no type) <-> invalid QOptional of type T
null QVariant (QString) <-> valid QOptional containing QString()
non-null QVariant containig QString("") <-> valid QOptional containing QString("")
non-null QVariant containing non-empty string <-> valid QOptional containing non-empty string

Second, i would like to hear some expertise about current implementation using "aligned" storage. Will it work? More, this implementation has a problem - QOptional(T) constructor can't be marked constexpr (as it uses placement new), which makes class useless for constant expressions at all. Should i add also c++11 implementation based on unions? (what would happen if we use c++98 compiled Qt with c++11 compiled app?)

Иван Комиссаров




More information about the Development mailing list