I have been reading this book: C++ High Performance and one example I encountered regarding move assignment was:
(as member function)
auto set_title(std::string && s){
title_ = std::move(s);
}
however unless the s variable is coming out of an equation as an rvalue reference, we also have to call
set_title(std::move(variable_name))
in order to trigger the set_title using the rvalue signature.
I did check other places like cppreference and indeed the move inside the function definition seems to be a common behavior.
I am particularly interested/confused about the std::move
of the assignment in the function, since the variable is already parsed as a rvalue reference, why doing std::move
again?
Thanks!