Condividi tramite


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)

Return Value

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

Remarks

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.

Requirements

Header: <utility>

Namespace: std

See Also

Reference

<utility>

Lvalues and Rvalues

Other Resources

<utility> Members

Move Semantics and Perfect Forwarding