I was reading the chapter 13 of C++ Primer when I read :
"It is essential to realize that the call to move promises that we do not intend to use [an rvalue] again except to assign to it or to destroy it. After a call to move, we cannot make any assumptions about the value of the moved-from object."
"We can destroy a moved-from object and can assign a new value to it, but we cannot use the value of a moved-from object."
So I wrote this code to see if I can't actually use a rvalue twice :
#include <iostream>
int main(int argc, const char * argv[]) {
int&& rvalue = 42;
int lvalue1 = std::move(rvalue);
std::cout << "lvalue1 = " << lvalue1 << std::endl;
int lvalue2 = std::move(rvalue);
std::cout << "lvalue2 = " << lvalue2 << std::endl;
return 0;
}
But according to the output of this code, C++ Primer is wrong and I can use the value of a moved-from object several times (I built with the C++11 standard) :
lvalue1 = 42
lvalue2 = 42
I don't understand...