I am wondering what is the origin of move semantics in C++? In particular was it invented specifically for this language or there was something similar in other language(s)? In the latter case could you give some references.
Move semantics is a set of semantic rules and tools of the C++ language. It was designed to move objects, whose lifetime expires, instead of copying them. The data is transferred from one object to another. In most cases, the data transfer does not move this data physically in memory.
One of the most important concepts introduced in C++11 was move semantics. Move semantics is a way to avoid expensive deep copy operations and replace them with cheaper move operations.
A little bit about std::moveMove Semantics is an extremally important concept for one to understand talking about programming in c++. It is a fundamental aspect of the language that may not be that obvious and even more for one coming from another language such as Swift, C#, or Java.
std::move is used to indicate that an object t may be "moved from", i.e. allowing the efficient transfer of resources from t to another object. In particular, std::move produces an xvalue expression that identifies its argument t . It is exactly equivalent to a static_cast to an rvalue reference type.
There doesn't appear to be any kind of specific ancestor to the concept. The origin of C++'s move semantics, as noted in the original proposal, was discussion in newsgroups:
Move semantics in various forms has been discussed in C++ forums (most notably comp.lang.c++.moderated) for years.
To my mind, they are tightly coupled with C++'s notion of lvalues and rvalues which, if I'm not mistaken, is purely a C++ concept. A language that doesn't have lvalues, rvalues and their new C++11 friends doesn't need move semantics in the way that C++ implements them.
More generally, though, the concept of moving stuff around rather than copying is just a fundamental concept. Whenever you write a linked list and you "swap elements" by actually just swapping pointers to them, you're doing a "move". Basically.
You can read "A Proposal to Add Move Semantics Support to the C++ Language" to get more information on the motivation behind the concept, as well as why this needs to have direct language support rather than being implemented using library facilities.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With