Move semantics is faster than copy semantics, when the compiler can replace expensive copy operations by cheaper move operations, that is, when it can replace a deep copy of a big object by a shallow copy of the pointer to the big object. Hence, classes using the pimpl idiom in combination with move semantics...
Tag: C++11
Performance Gains Through C++11 Move Semantics
We explore when and how our code benefits most from equipping classes with move constructors and assignment operators. We analyse in detail, which constructors and assignment operators (move or copy) are called for C++98 and C++11 when we insert or emplace objects into containers, when we initialise containers and when we shuffle and sort...
Simplifying Loops with C++11 in Qt Ways
Recently, I looked through the code base of a medium-sized project to see how I could simplify handwritten for-loops by using C++11’s new range-based for and STL algorithms with lambda expressions. The results in short: Range-based for makes loops simpler, easier to understand and often faster. STL algorithms are often a bit harder to...
Using C++11 Initializer Lists in Qt Ways
In this post, I want to show some examples how C++11’s initializer lists can improve some typical Qt code. I’ll show how C++11 makes the initialisation of container-type variables very simple and how it makes static const data members possible at all....