[Development] C++11 for Examples

Thiago Macieira thiago.macieira at intel.com
Tue Mar 3 22:49:29 CET 2015


On Tuesday 03 March 2015 16:15:59 Matthew Woehlke wrote:
> > Unlikely, we don't create new template classes in our examples. There are
> > also very few classes in the Qt sources that would benefit from it.
> 
> I can think of a few that *might*... QString::arg,

I have a replacement for QString::arg (called QStringArgBuilder) that I've 
been keeping for now a year and a half. It's a near drop-in replacement with a 
big advantage that it makes proper use of rvalue-qualified members and allows 
arg() to modify in-place, but it has two big drawbacks:

 1) like QStringBuilder, it returns an object that isn't exactly QString, 
which means it introduces a slight source incompatibility. See 
https://codereview.qt-project.org/107694

 2) completion in Qt Creator doesn't work anymore for the first arg() call 
because of the variadic template perfect forward to QStringArgBuilder.

> QMetaObject::invokeMethod... anything that takes a pseudo-variadic list
> (there are a few places), maybe. (Although I can imagine that the
> internals may not in all cases be conducive to being rewritten as true
> variadics.)

Right, like QDBusAbstractInterface and QDBusPendingReply. But that's 3 classes 
out of 1200+. I mentioned that there are very few :-)

> And on a different note... what about initializer lists? I literally
> just today was writing:
> 
>   QProcess process;
>   process.start("cmd", {"arg", "arg", QString::number(value) ...});

Why wouldn't that already work?

> I'm not going to start a war on omission of class types (although I do
> find it can be quite convenient, especially for things where the type is
> obvious, e.g. lots of places that take a QRect, QPoint, QSize, etc.),
> but I could see making use of the ability to pass vectors in-place via
> initializer.

Those don't need initialiser lists. The uniform initialisation syntax would 
simply call the appropriate constructor.

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




More information about the Development mailing list