Skip to main content
9 of 11
edited tags
sbi
  • 225k
  • 46
  • 267
  • 447

Advantages of using forward

In perfect forwarding, std::forward is used to convert the named rvalue references t1 and t2 to unnamed rvalue references. What is the purpose of doing that? How would that affect the called function inner if we leave t1 & t2 as lvalues?

template <typename T1, typename T2> void outer(T1&& t1, T2&& t2) { inner(std::forward<T1>(t1), std::forward<T2>(t2)); } 
Steveng
  • 6.1k
  • 4
  • 19
  • 7