I know if you use std::move(s)
, then the s can not use again, But I have some questions.
If I don't do move constructor/assignment operator
, Does the variable still exist?
// not do assignment
void test2(string &&t) {
return;
}
void test1(string &&s) {
test2(std::move(s));
}
int main()
{
string s("123");
test1(std::move(s));
cout << "s: " << s << endl;
}
Above test seems it exist, So is this the best practice to use std::move in a while loop below.
// do assignment
bool test4(string &&t) {
if (condition) {
return false;
}
string m = std::move(t);
return true;
}
void test3(string &&s) {
while(true) {
if( test4(std::move(s)) ) {
break;
}
}
}
seems if you don't do move assignment operator
the s is still exist next loop, when it success then it do move assignment operator
and break the loop, There seems to be no logical error, but I want to know if this is the best practice ? Because you need to handle data carefully.