引用声明是否为引用对象引入了新名称

引用声明是否为引用对象引入了新名称

本文介绍了引用声明是否为引用对象引入了新名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在中,我们了解到RVO不能应用于 p .first

In this question we've learnt that RVO cannot be applied to an expression like p.first.

在注释中,还建议RVO通常不适用于 r 之后声明如 auto& r = p.first 。不太清楚标准是否强制这种行为。

In comments it was also suggested that RVO is generally not applied to an expression like r after a declaration like auto& r = p.first. It is less clear whether the standard mandates this behaviour.

在下面的代码中,是也被称为 o 的对象的 r a 名称 return 语句中形成表达式时允许使用RVO?

In the following code, is r a name of the object also known as o, to the extent that RVO is permissible when it forms the expression in a return statement?

int o = 42;
int& r = o;


推荐答案

解决了与对象不同的引用没有实际名称的事实的值。该问题已由解决,它扩展了变量的概念以包含引用,从而给出它们的名称。

现在[basic] / 6读(所有重点由我):

CWG #633 addressed the fact that references, unlike objects, didn't have actual names. It was resolved by N2993, which extended the notion of a variable to encompass references, thereby giving them names.
Now [basic]/6 reads (all emphasis by me):

引用表示变量 - 引用 - 不是引用引用的对象。虽然引用通常被解释为对象/函数的其他名称,但在标准术语中,定义是明文错误的。

The name of a reference denotes that variable - the reference - not the object that the reference refers to. Although references are commonly explained as being "other names of objects/functions", in standard terms that definition is plain wrong.

由于上述文件直到2009年才被采纳,并且您已将:一可以认为该文件是C ++ 03的回顾性校正。但是,在C ++ 03中,严格来说,引用不是一个实体(这是通过),因此其声明中的标识符从不被视为名称(参见[basic] / 4,名称必须表示标签或实体) - 因此复制elision不适用,再次。

Since the above paper was not adopted until 2009, and you tagged c++03: One can consider the paper as a retrospective correction of C++03. However, in C++03, strictly speaking, a reference is not an entity (this was rectified by CWG #485) and therefore the identifier in its declaration is never treated as a name (see [basic]/4, a name must denote a label or entity) - hence copy elision doesn't apply, again.

这篇关于引用声明是否为引用对象引入了新名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 12:33