Collapse the table of content
Expand the table of content


Preserves the reference type (either lvalue or rvalue) of the argument from being obscured by perfect forwarding.

template<class Type>
    Type&& forward(typename identity<Type>::type& _Arg)

Returns an rvalue reference if _Arg is an rvalue, or an lvalue reference if _Arg is an lvalue.

Perfect forwarding allows a method to accept an argument without requiring a specific reference type. This avoids having to define several methods that vary only by the reference type of the arguments to cover all the possible combinations. The result of a perfect forward is that the reference type for an argument becomes obscured. The forward function preserves the reference type for later use in the code statement.

You must call forward using an explicit template parameter.

Header: <utility>

Namespace: std


Other Resources

Move Semantics and Perfect Forwarding

Community Additions

© 2015 Microsoft