Perfect Forwarding

suggest change

Remarks

Perfect forwarding requires forwarding references in order to preserve the ref-qualifiers of the arguments. Such references appear only in a deduced context. That is:

template<class T>
void f(T&& x) // x is a forwarding reference, because T is deduced from a call to f()
{
    g(std::forward<T>(x)); // g() will receive an lvalue or an rvalue, depending on x
}

The following does not involve perfect forwarding, because T is not deduced from the constructor call:

template<class T>
struct a
{
    a(T&& x); // x is a rvalue reference, not a forwarding reference
};

C++17 will allow deduction of class template arguments. The constructor of “a” in the above example will become a user of a forwarding reference

a example1(1);
  // same as a<int> example1(1);

int x = 1;
a example2(x);
  // same as a<int&> example2(x);

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Perfect forwarding:
* Perfect Forwarding

Table Of Contents
8 Arrays
11 Loops
39 Streams
51 Unions
56 Lambdas
60 SFINAE
62 RAII
67 Sorting
69 Perfect forwarding
84 RTTI
87 Scopes
104 Profiling
107 Recursion
117 Iteration
125 Alignment
134 Semaphore
136 Debugging
139 Mutexes
142 decltype