Monday, July 10, 2017

C++11: Rvalue References

To eliminate a copy of a source object during construction or assignment, a destination can be defined as an rvalue, so that a move is made instead of a copy. The symbol for an rvalue reference is &&. Here is an example:
#include
int main()
 {
    int&& i = 3;
    std::cout << i << std::endl;
    return 0;
}
// Output: 3
The above problem doesn’t look too useful, but imagine that the ‘3’ was an invisible temporary, which is another form of an rvalue.


No comments:

Post a Comment