From 7519dc025ccc1f627c6c19fcf4f7870184c8b727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BD=92=E6=95=85=E9=87=8C?= <3326284481@qq.com> Date: Mon, 4 Mar 2024 11:36:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E4=BD=BF=E7=94=A8std::forwar?= =?UTF-8?q?d=EF=BC=9F=20#104=20=E8=A7=A3=E5=86=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- google-cpp-styleguide/others.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/google-cpp-styleguide/others.rst b/google-cpp-styleguide/others.rst index 8def80e..27f742c 100644 --- a/google-cpp-styleguide/others.rst +++ b/google-cpp-styleguide/others.rst @@ -42,11 +42,13 @@ .. tip:: - 只在定义移动构造函数与移动赋值操作时使用右值引用. 不要使用 ``std::forward``. + 仅在下面列出的某些特殊情况下使用右值引用. 定义: - 右值引用是一种只能绑定到临时对象的引用的一种, 其语法与传统的引用语法相似. 例如, ``void f(string&& s)``; 声明了一个其参数是一个字符串的右值引用的函数. + 右值引用是一种能绑定到右值表达式的引用类型, 其语法与传统的引用语法相似. 例如, ``void f(string&& s)``; 声明了一个其参数是一个字符串的右值引用的函数. + + 当标记“ ``&&`` ”应用于函数参数中的非限定模板参数时,将应用特殊的模板参数推导规则。这种引用称为转发引用. 优点: