Perfect forwarding - what's it all about?

smallB picture smallB · Jul 26, 2011 · Viewed 44.8k times · Source

Possible Duplicate:
Advantages of using forward

Could someone please explain to me what perfect forwarding is about?

Answer

J. Steen picture J. Steen · Jul 26, 2011

http://www.justsoftwaresolutions.co.uk/cplusplus/rvalue_references_and_perfect_forwarding.html

Why is this useful? Well, it means that a function template can pass its arguments through to another function whilst retaining the lvalue/rvalue nature of the function arguments by using std::forward. This is called "perfect forwarding", avoids excessive copying, and avoids the template author having to write multiple overloads for lvalue and rvalue references.