I was looking for std::forward
and found two links whose description could be interpreted differently.
cplusplus.com: Returns an rvalue reference to arg if arg is not an lvalue reference.
cppreference.com: Forwards lvalues as either lvalues or as rvalues, depending on T
The difference is the reference I think.
Can you tell me which is the correct explanation? Thanks.
found descriptions and compare
cppreference is correct, and cplusplus is wrong
from the standard §forward
template<class T> constexpr T&& forward(remove_reference_t<T>& t) noexcept; template<class T> constexpr T&& forward(remove_reference_t<T>&& t) noexcept;
- Mandates: For the second overload,
is_lvalue_reference_v<T>
isfalse
.- Returns:
static_cast<T&&>(t)
.
notes
T
is always specify explicitly, it's never deduced from the function parameter t
(or arg
)from cplusplus
Returns an rvalue reference to arg if arg is not an lvalue reference.
If arg is an lvalue reference, the function returns arg without modifying its type.
this is incorrect
T
is lvalue reference typeT
is rvalue (reference type)from cppreference
template< class T > constexpr T&& forward( std::remove_reference_t<T>& t ) noexcept;
Forwards lvalues as either lvalues or as rvalues, depending on T
template< class T > constexpr T&& forward( std::remove_reference_t<T>& t ) noexcept;
Forwards rvalues as rvalues and prohibits forwarding of rvalues as lvalues
this is correct.