Why doesn't my forward_ function work for rvalues?
A T&&
reference stops being a forwarding reference if you manually specify T
(instead of letting the compiler deduce it). If the T
is not an lvalue reference, then T&&
is an rvalue reference and won't accept lvalues.
For example, if you do forward_<int>(...)
, then the parameter is an rvalue reference and ...
can only be an rvalue.
But if you do forward_(...)
, then the parameter is a forwarding reference and ...
can have any value category. (Calling it like this makes no sense though, since forward_(x)
will have the same value category as x
itself.)