cpp/utility/forward

@1@ Forwards lvalues as either lvalues or as rvalues, depending on T.

When is a forwarding reference (a function argument that is declared as an rvalue reference to a cv-unqualified function template parameter), this overload forwards the argument to another function with the value category it had when passed to the calling function.

For example, if used in a wrapper such as the following, the template behaves as described below:


 * If a call to passes an rvalue, then  is deduced to  (not , , or ), and  ensures that an rvalue reference is passed to.
 * If a call to passes a const lvalue, then  is deduced to , and  ensures that a const lvalue reference is passed to.
 * If a call to passes a non-const lvalue, then  is deduced to , and  ensures that a non-const lvalue reference is passed to.

@2@ Forwards rvalues as rvalues and prohibits forwarding of rvalues as lvalues.

This overload makes it possible to forward a result of an expression (such as function call), which may be rvalue or lvalue, as the original value category of a forwarding reference argument.

For example, if a wrapper does not just forward its argument, but calls a member function on the argument, and forwards its result:

where the type of arg may be

Attempting to forward an rvalue as an lvalue, such as by instantiating the form with lvalue reference type T, is a compile-time error.

Complexity
Constant.