in C++, is std::move still preferred when calling a function that takes in a const reference?

Of the two versions of function calls below, is the one with std::move still preferred?

void myFunc(const std::string& myStr){

std::string MyStr = "my string";

//For these 2 versions, should I still prefer std::move here to save a value copy, even when the function itself takes in a reference?

>Solution :

When passing a value by reference std::move doesn’t make any sense, because no instantiation is happening here, and there would be no side effects (provided you don’t want to alter overload function candidate)

Thus for this particular case there is no any difference and you don’t need std::move

Leave a Reply