+ 2

[solved] Is STL really improved with C++11 Move semantics?

I used to hear a lot that move semantic has major improvement on STL. Just build your legacy code after adding move semantics [in case you have some special member functions defined or else move semantics for your class is provided by compiler). This will give a performance improvement. Just thought to evaluate this. Refer code below: I have a class which allocates memory on heap and rule of 5 has been followed. Created a vector of this class and emplaced back an element (class object) When second emplace back is done, obviously capacity is same as size and re allocation will happen. I was expecting class move semantic rather than copy to avoid frequent heap allocations. Is my expectation not fulfilled my C++11 move semantic? Am I missing something? What to be done in existing code so that vector does use move semantic for class object when size is capacity and doing reallocation of elements?

2nd Dec 2022, 8:06 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
3 Answers
+ 3
Done now Noexcept was missing for move constructor and move assignment
2nd Dec 2022, 6:44 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 2
Not able to add link of code as size limit exceeded. Here is my code for reference : https://code.sololearn.com/csN54ox1bj4k/?ref=app
2nd Dec 2022, 8:08 AM
Ketan Lalcheta
Ketan Lalcheta - avatar