I have seen lots of discussions about using std::move
on a function return value (like this), and I know it's unnecessary for these cases. But what if I want to use the std::move
semantic when receiving a function output like the codes below:
std::vector<double> funcA()
{
std::vector<double> out(10000, 0.0);
return out;
}
int main()
{
auto out = std::move(funcA());
return 0;
}
Is this a good use case for std::move
? My understanding is move
here can avoid a copy of the returned vector, especially when the vector size is very large. Please correct me if I'm wrong. Thanks so much!
Aucun commentaire:
Enregistrer un commentaire