转发引用是否仍然是右值引用?

编程入门 行业动态 更新时间:2024-10-27 11:15:21
本文介绍了转发引用是否仍然是右值引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我仍然对为支持移动和转发而发明的规则感到困惑.我仍然不确定的一件事是:

是转发参考,只是右值参考(带有是否应用了参考折叠规则)?

如果它是右值引用,那么为什么要执行该功能:

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).

更多推荐

转发引用是否仍然是右值引用?

本文发布于:2023-07-30 16:18:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1250983.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:仍然是

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!