Hello everyone, I am learning about std::forward which is confusing.
The returned value type of std::forward keeps all the traits of its parameter.
If the real parameter is rvalue like 40 in the following code, after std::forward(40), the returned value type is rvalue reference, since it is anonymous, so it can be used as a rvalue (real parameter) passed to rvalue formal parameter v1 in f(int &&v1, int &v2). (Guess the logic up to now is correct)
While for a lvalue real parameter i, after std::forward, the returned type is lvalue reference. If use the logic in last paragraph, it is also an anonymous variable. Then it should also be regarded as a rvalue and should not be passed to lvalue reference v2 in f(int &&v1, int &v2). But it works.
the lvalue and rvalue are the traits of the expression. the value categories includes lvalue, rvalue(prvalue, and xvalue)...
For the std::forward<int>(40), (with a rvalue ref as returned type), it is a xvalue expression, which is still rvalue category instead of a lvaue, and so it can be passed to rvalue ref formal parameter.
While the std::forward<int>(i), (with a lvalue ref as the returned type), is lvalue expression, so it can be binded to lvalue ref.