[Development] QOptional

Thiago Macieira thiago.macieira at intel.com
Thu Aug 21 00:14:42 CEST 2014


On Wednesday 20 August 2014 23:17:32 Olivier Goffart wrote:
> On Wednesday 20 August 2014 22:04:24 Иван Комиссаров wrote:
> > 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.
> 
> It's valid in C++14
> We need a new macro that only expends to constexpr with C++14.
> Q_DECL_RELAXED_CONSTEXPR?
> Q_DECL_CONSTEXPR_X?
> Q_DECL_CONSTEXPR_14?

I prefer Q_DECL_RELAXED_CONSTEXPR, but I'd rather we didn't do that at all. If 
possible, we should make it C++11 constexpr.

> > 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?)
> 
> Good idea.
> Just Make sure it is binary compatible :-)

The problem is getting the alignment right. Q_ALIGNOF works everywhere, but 
Q_DECL_ALIGNED doesn't. So you have to put it in a union with a double and a 
pointer, but that's not necessarily layout-compatible with the Q_DECL_ALIGNED 
equivalent (think of 16-byte-aligned types).

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Development mailing list