Nothing is Better Than copy or move

By Roger Orr

C++11 introduced 'move semantics' to facilitate transferring the contents of one object to another more efficiently than creating a copy and then erasing the original. This is particularly focussed on optimising the performance of temporary objects, such as when passing them into or out of a function call.

However, in all the discussions about copying and moving it is easy to forget that not creating an object in the first place may be even more efficient. This can be something done by design choice, or an optimisation applied during compilation. For example, introduction of a temporary object by copying can be removed; this is is called 'copy elision' in C++ and has been permitted in the language for many years.

C++17 adds some additional specification around the creation of temporary variables with the phrase 'temporary materialization'.

This presentation will look at some 'worked examples' of how this behaves in practice, and some things to be aware of.