12

Looking at the documentation for std::forward,

template< class T >
constexpr T&& forward( typename std::remove_reference<T>::type& t ) noexcept;
template< class T >
constexpr T&& forward( typename std::remove_reference<T>::type&& t ) noexcept;

Both functions return T&&, which (correct me if I'm wrong) collapses to

  • T& if T is an lvalue reference
  • T&& if T is an rvalue reference, or if T is not a reference

For an arbitrary type T which may be a reference, does reference collapsing always cause forward<T> to do the same as forward<T&&>?

If so, is there any reason to use forward<T&&>?

Taylor Nichols
  • 588
  • 2
  • 13

1 Answers1

16

Does reference collapsing always cause forward<T> to do the same as forward<T&&>?

Yes.

[I]s there any reason to use forward<T&&>?

No.

Note that this is assuming that the only forwards in view are the two overloads you showed in std::.

T.C.
  • 133,968
  • 17
  • 288
  • 421