The difference between std::move
and std::forward
well known, we use the latter to maintain the category of values โโof the redirected object, and the former to refer to rvalue to include the semantics of movement.
In efficient modern C ++, there is a rule that says
use std::move
for rvalue links, std::forward
for universal links.
However, in the following scenario (and scenarios where we do not want to change the category of values),
template <class T> void f(vector<T>&& a) { some_func(std::move(a)); }
where a
not a link for forwarding, but a simple link to rvalue, wouldn't the following do the same?
template <class T> void f(vector<T>&& a) { some_func(std::forward<decltype(a)>(a)); }
Since it 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 this?
void f(vector<T>&& a) { some_func(FWD(a)); }
Are there two ways to write this equivalent?
source share