A move() template function tells the compiler to
move from source instead of first copying from source. The source is changed to a "cheap default", i.e., an object that is inexpensive to create and delete. Here is an example:
#include
int main()
{
int i = 3;
int & ri = i;
int j = 4;
int & rj = j;
rj = std::move(ri);
std::cout << rj << std::endl;
return 0;
}
// Output: 3
The move() template function is equivalent to a
static_cast to an rvalue reference type.
References: https://isocpp.org/wiki/faq/cpp11-language#rval; http://en.cppreference.com/w/cpp/utility/move
No comments:
Post a Comment