Alright, time to get dirty in C++ land. We’re gonna talk about move semantics (also known as r-value references), one of the big new featuresets in C++11. Why do they matter? How do you use them?
Backstory: Copying vs Moving
Look at this code:
std::vector<MyClass> myCollection;
MyClass myItem;
myCollection.push_back(myItem);
When you run this code, you end up with two instances of MyClass
that look the same: myItem
, and myCollection[0]
, which is a copy of whatever myItem
looked like at push_back()
time.… Read the rest