rvalue reference(右值引用)是 C++(从 C++11 起)引入的一种引用类型,写作 T&&。它主要用于绑定临时对象(右值),从而支持移动语义(move semantics)与完美转发(perfect forwarding),以减少不必要的拷贝、提升性能。
注:在特定语境下(如模板类型推导),T&& 可能表现为“转发引用(forwarding reference)”,这是相关但更细分的概念。
/ˈɑːrˌvæljuː ˈrɛfərəns/
An rvalue reference can bind to a temporary object.
右值引用可以绑定到一个临时对象。
By taking the parameter as an rvalue reference, the function enables move construction and avoids an expensive deep copy.
通过把参数设为右值引用,该函数可以触发移动构造,从而避免代价高昂的深拷贝。
rvalue 源自早期编程语言与编译原理中的表达式分类:可出现在赋值号右边的值常被称为 r-value(right-hand value,右侧的值),强调其通常是临时结果或不可作为赋值目标的表达式。
reference 来自拉丁语系词根,意为“指向/引用”。合在一起,rvalue reference 就是“指向右值(临时值)的引用”。这一术语在 C++11 标准化过程中固定下来,用于描述 && 引用类型及其语义。
&&)std::move 与转发)