I get that C++ 11 has introduced the new move semantics and as consequence data containers are changed to meet the new definitions and specifications of the language, I don’t really get how the standard containers benefits from them.
Also I think that I have got what an Rvalue is and how the move semantics act, the problem is i don’t see any useful point about this, moving things and changing their labels doesn’t sound like a meaningful feature.
I can ask for a good resource about how map, list, vector, ... are changing in the new C++11 ?
The reason RValues and LValues were introduced is it can be much faster to move object data than it is to perform a copy on it. The performance gain is mainly because of internally stored pointers that do not need to be replicated during a move, which would otherwise involve needless malloc calls and memcpys. For instance,
std::stringcontains a pointer to achararray that can be very large. Copying it would involve copying the data in thatchararray, moving simply involves copying the pointer to that data.With respect to LValues and RValues, the only things, of which I’m aware, that have changed, is now we have a shiny new constructor to play with, and many of the member functions have been rewritten to take advantage of move semantics.
For instance,
std::vectornow has astd::vector::vector(std::vector&& move)ctor, and functions likepush_backhave been changed to also accept RValues.This should be, for the most part, seemless to you. If you’re writing a library, rather than just using one, you need to know this, and URefs too.