std::move
does not mean move
action. It casts. signals that it can be moved
Unconditionally casts its argument to an rvalue reference, and thereby signals that it can be moved if its type is move-enabled.
You are just binding an rvalue reference to the vector you pass; not moving.
Compare the example:
Output:
3
temp is 3
v is 0
0
#include <iostream>
#include <vector>
std::vector<int> v{ 1,2,3 };
void Method2(const bool& b, std::vector<int> temp)
{
std::cout << "temp is "<<temp.size()<<std::endl;
std::cout <<"v is " <<v.size() << std::endl;
}
bool Method1()
{
std::cout << v.size() << std::endl;
Method2(true, std::move(v));
std::cout << v.size() << std::endl;
return true;
}
int main()
{
Method1();
}
Best regards,
Minxin Yu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.