The second version, the one taking a reference, is a tiny bit more efficient, since there's no separate object constructed for the function parameter. You would find this kind of style in generic library code where you don't want to impose any unnecessary cost on the user.
The first version is a bit easier to read and to remember, and allows the slightly more general advice to "pass things by value which you want to own". This advice doesn't apply quite perfectly in your case, but it does in other cases. Consider a class that owns a string:
struct Foo
{
std::string s_;
Foo(std::string s) : s_(std::move(s)) {}
};
By passing the constructor argument by value, you can now construct a Foo
from both an lvalue and an rvalue string, and you leave the decision whether to copy or to move to the constructor of std::string
, rather than worry about it yourself. This reduces complexity (imagine you had five such arguments).
As a final word of general advice, bear in mind that the C++ standard library considers any value that is bound to an rvalue reference to be unaliased, i.e. referred to only by that reference and nobody else. This is an important "hidden" semantic assumption. So even though an rvalue reference is a reference and you could in principle use it to refer to some shared state, don't go overboard with that, since it would be unexpected and surprising.