One of the C++0x improvements that will allow to write more efficient C++ code is the unique_ptr smart pointer (too bad, that it will not allow moving through memmove() like operations: the proposal didn’t make into the draft).
What are other performance improvements in upcoming standard? Take following code for example:
vector<char *> v(10,"astring");
string concat = accumulate(v.begin(),v.end(), string(""));
The code will concatenate all the strings contained in vector v. The problem with this neat piece of code is that accumulate() copies things around, and does not use references. And the string() reallocates each time plus operator is called. The code has therefore poor performance compared to well optimized analogical C code.
Does C++0x provide tools to solve the problem and maybe others?
Yes C++ solves the problem through something called move semantics.
Basically it allows for one object to take on the internal representation of another object if that object is a temporary. Instead of copying every byte in the string via a copy-constructor, for example, you can often just allow the destination string to take on the internal representation of the source string. This is allowed only when the source is an r-value.
This is done through the introduction of a move constructor. Its a constructor where you know that the src object is a temporary and is going away. Therefore it is acceptable for the destination to take on the internal representation of the src object.
The same is true for move assignment operators.
To distinguish a copy constructor from a move constructor, the language has introduced rvalue references. A class defines its move constructor to take an rvalue reference which will only be bound to rvalues (temporaries). So my class would define something along the lines of:
Here is a very good and detailed article on move semantics and the syntax that allows you to do this.