std::forward is similar to std::move . It is just a static_cast to rvalue reference . But it is slightly different than std::move , std::forward is a conditional cast that only cast the type to rvalue-reference if some condition is satisify. Let dive deeper in it!
First of all, let look at a custom implementation of std::forward , this is not the exact definition in the STL, but it is close enough.
namespace std { template < typename T > __attribute__ (( always_inline )) constexpr T && forward ( std :: remove_reference_t < T >& t ) noexcept { return static_cast < T &&> ( t ); }
template < typename T > __attribute__ (( always_inline )) constexpr T && forward ( std :: remove_reference_t < T >&& t ) noexcept { static_assert ( !…