[Development] QOptional

Milian Wolff mail at milianw.de
Wed Aug 20 20:16:22 CEST 2014


On Wednesday 20 August 2014 22:04:24 Иван Комиссаров wrote:
> 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?)

This might be relevant (and the upcoming next parts to that blog series): 
http://talesofcpp.fusionfenix.com/post-17/eggs.variant---part-i

Bye
-- 
Milian Wolff
mail at milianw.de
http://milianw.de



More information about the Development mailing list