If you have a function parameter that is intended to be moved into a variable within the function, would you have want to use pass by reference instead of pass by value?
For example, is there ever any benefit to using
void func(T &object2move)
{
T obj{std::move(object2move)};
}
vs.
void func(T object2move)
{
T obj{std::move(object2move)};
}
In addition to the above, is the only case where you want to use the following code when you only want func
to take in an rvalue?
void func(T object2move)
{
T obj{object2move};
}
Is the answer to these questions dependent on what T
is?