The declaration of foo
:
void foo(std::string && s) {
func(s, ':');
}
means that it can accept an rvalue reference, and this information is used for method resolution. However, within foo
the parameter has a name, and is therefore as an lvalue reference. Basically it has decayed to a lvalue reference.
If you want to treat it as an rvalue reference when calling func
then you need to covert it back to an rvalue refence by turning it back into an unnamed instance. This is what std::move
accomplished.