3 ms·
the article does not mention rvalues and move semantics (i think it's one of the bigest features). here is an explanation http://stackoverflow.com/questions/68
by MichaelMoser123 12y ago
the article does not mention rvalues and move semantics (i think it's one of the bigest features).
here is an explanation http://stackoverflow.com/questions/6815685/move-semantics-what-its-all-about http://stackoverflow.com/questions/6815685/move-semantics-wh...
it is supposed to save extra copies like here
string a("a");
string b("b");
string c = a + b; // creates temporary object that is copied into C by value - the temporary is just a 'full copy'; so that for the temporary it needs an extra allocation and strcpy and free.
the fix is to add the following to the string class
string(string &&r)
{
...
}
string &operator=(string &&r)
{
...
}
so the operator with the && receives and 'rvalue' reference - which is a special reference to just this temprorary and the implementation of this is supposed to swap the data of the temporary with that of the this object; the temporary is then discarded.
- zeroonetwothree 12y agoThis isn't new in C++14 though.
- MichaelMoser123 12y agolambda functions and the auto keyword aren't new either - in C++11 already.
- ternaryoperator 12y agoauto keyword was in C++11, but as this article points out, it does a whole lot more in C++14.
- capisce 12y agoYes, but the use of auto to auto-deduce the return type is new in C++14, as well as the use of auto as a return type for lambdas to produce generic lambdas - generic functions without having to use template syntax.