0

Possible Duplicate:
Advantages of using forward

The idea of perfect fowarding is to forward the exact CV qualifiers in a templates to other templates.

However, it uses the RValue-references feature, which means it cannot bind to named variables. (I think?)

If it can't bind to named variables, how is the forwarding "perfect"?

Community
  • 1
  • 1
Billy ONeal
  • 101,029
  • 52
  • 303
  • 540
  • Hi, Billy. [This article](http://www.justsoftwaresolutions.co.uk/cplusplus/rvalue_references_and_perfect_forwarding.html) says: "When you combine rvalue references with function templates you get an interesting interaction: if the type of a function parameter is an rvalue reference to a template type parameter then the type parameter is deduce to be an lvalue reference if an lvalue is passed, and a plain type otherwise." Does that answer your question? – Nemo Jun 18 '11 at 05:09
  • @GMan: I agree. Voted to close my own question lol. – Billy ONeal Jun 18 '11 at 05:09
  • @Nemo: So it really isn't an RValue Reference at all then? – Billy ONeal Jun 18 '11 at 05:10
  • @Billy: That is my understanding. They just decided to define wacky semantics here "because we know it cannot break existing code". At least, that is my understanding... I admit I do not fully have my head around it yet. – Nemo Jun 18 '11 at 05:12
  • 1
    @GMan: If it's not about CV qualifiers, then why does the answer you linked to refer completely about whether `const` is attached to the reference or not? – Billy ONeal Jun 18 '11 at 05:13
  • That comment auto-deletion is damn annoying. @Billy: Because `const` helps you detect the *value category* of a value. Forwarding is about preserving the value category, so lvalues stay lvalues and rvalues stay rvalues. If you have a non-const reference and const reference overload of a function, lvalues go to the former and rvalues go to the latter. (This is unmaintainable, though, which is why we use rvalue references and reference collapsing rules. So the portion of the answer you're referring to intends to demonstrate why that is.) – GManNickG Jun 18 '11 at 06:02

0 Answers0