[Qt-creator] Using C++11 in Creator's source

Erik Verbruggen erik.verbruggen at digia.com
Fri Mar 14 14:38:03 CET 2014


On 7-3-2014 9:25, Ziller Eike wrote:

> Optionally you can use the “auto” keyword in the following cases. If in doubt, if auto could make the code less readable, do not use auto. Keep in mind that code is read much more often than written.
>
> * When it avoids repetition of a type in the same statement. You should explicitly mention any “const”, “&” and “*” as well, even if they were implicit.
>     - auto *something = new MyCustomType(…);
>     - auto *somethingElse = qobject_cast<MyOtherCustomType *>(sender());
>     - auto myFunnyListOfThings = QStringList() << QLatin1String(“FooThing”) << QLatin1String(“BarThing”);
>
> * When assigning iterator types.
>     - auto it = myFunnyListOfThings.const_iterator();

I'd like to propose to add:
  * When taking simple copies:
     - auto pendingDocumentInfos = m_pendingDocumentInfos;

in code like:
class Asdf {
private:
     QHash<QString, QVector<ModelItemInfo::Ptr>> m_pendingDocumentInfos;
     void runSafely() {
         QMutexLocker locker(&theLock);
	auto pendingDocumentInfos = m_pendingDocumentInfos;
         locker.unlock();
         // etc.
     }
};

-- Erik.



More information about the Qt-creator mailing list