转发引用是否仍然是右值引用? [英] Is a forwarding reference still an rvalue reference or not?
问题描述
我仍然对为支持移动和转发而发明的规则感到困惑.我仍然不确定的一件事是:
是转发参考,只是右值参考(带有是否应用了参考折叠规则)?
如果它是右值引用,那么为什么要执行该功能:
template< typename T>void func(T&);
不仅接受右值,还接受左值吗?
(显然)在替换 T
之前, T&&
是右值引用./p>
在替换 T
之后(并且折叠引用之后), T&
要么仍然是右值引用(如果 T
为而不是引用),或成为左值引用(如果 T
是左值引用).
I'm still confused by the rules invented to support moving and forwarding. One thing I'm still not sure about is:
Is a forwarding reference just an rvalue reference (with reference collapsing rules applied)?
If it is an rvalue reference, then why does the function:
template<typename T>
void func(T&&);
accept not only rvalues, but also lvalues?
Before T
is substituted, T &&
is an rvalue reference (obviously).
After T
is substituted (and after references are collapsed), T &&
either remains an rvalue reference (if T
is not a reference), or becomes an lvalue reference (if T
is an lvalue reference).
这篇关于转发引用是否仍然是右值引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!