The distinction between std::move
and std::forward
is well known, we use the latter to preserve the value category of a forwarded object and the former to cast to rvalue reference in order to enable move semantics.
In effective modern C++, a guideline exists that states
use
std::move
on rvalue references,std::forward
on universal references.
Yet in the following scenario (and scenarios where we don't want to change value category),
template <class T>
void f(vector<T>&& a)
{
some_func(std::move(a));
}
where a
is not a forwarding reference but a simple rvalue reference, wouldn't it be exactly the same to do the following?
template <class T>
void f(vector<T>&& a)
{
some_func(std::forward<decltype(a)>(a));
}
Since this can be easily encapsulated in a macro like this,
#define FWD(arg) std::forward<decltype(arg)>(arg)
isn't it convenient to always use this macro definition like so?
void f(vector<T>&& a)
{
some_func(FWD(a));
}
Aren't the two ways of writing this exactly equivalent?