我仍然对为支持移动和转发而发明的规则感到困惑.我仍然不确定的一件事是:
是转发参考,只是右值参考(带有是否应用了参考折叠规则)?
如果它是右值引用,那么为什么要执行该功能:
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).
更多推荐
转发引用是否仍然是右值引用?
发布评论