Reputation: 9432
I am wondering about forwarding:
The standard implements std::forward
basically with two overloads:
T
)template<typename T>
T&& forward(lvalue_Reference v){
return static_cast<T&&>(v);
};
template<typename T>
T&& forward(rvalue_Reference v){
// static-assert: T is not an lvalue-Reference
return static_cast<T&&>(v);
};
First case comes to play when
template<typename T>
void foo(T&& a) { doSomething(std::forward<T>(a)); /* a is lvalue -> matches 1. overload */ }
The second case makes sense, but what is an example of triggering it?
Upvotes: 1
Views: 86
Reputation: 319
I believe this is a duplicate of:
What is the purpose of std::forward()'s rvalue reference overload?
Please also read the included paper:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2951.html
Upvotes: 1