Here is code below. Why if I replace typename remove_reference<S>::type&
with S&
it won't work nicely? (I mean a type will be deduced wrong)
If I pass an rvalue (let int be int), then S
will be deduced as int
, a
's type is int&
, forward()
returns int&&
(rvalue).
If I pass an lvalue (int
) S
will be deduced as int&
, a
's type is int& & ->int&
, forward()
returns int& &&->int&
. everything works well, so why do we need that remove_reference
?
template<class S>
S&& forward(typename remove_reference<S>::type& a) noexcept
{
return static_cast<S&&>(a);
}