template <typename T>
void pass(T&& v) {
reference(v);
}
You are using a Forwarding reference here quite alright, but the fact that there is now a name v
, it's considered an lvalue
to an rvalue reference.
Simply put, anything that has a name is an lvalue
. This is why Perfect Forwarding is needed, to get full semantics, use std::forward
template <typename T>
void pass(T&& v) {
reference(std::forward<T>(v));
}
What std::forward<T>
does is simply to do something like this
template <typename T>
void pass(T&& v) {
reference(static_cast<T&&>(v));
}
See this;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…