Export (0) Print
Expand All

forward

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

Reference

Other Resources

Move Semantics and Perfect Forwarding
Show:
© 2015 Microsoft