问题描述
在C ++ 03中,表达式是 rvalue 或 lvalue 。
在C ++ 11,表达式可以是:
- rvalue
- 左值
- xvalue
- glvalue
- prvalue
两个类别已经成为五个类别。
- 这些新类型的表达式是什么?
- 这些新类别与现有的rvalue和lvalue类别?
- C ++ 0x中的rvalue和lvalue类别是否与C ++ 03中相同?
- 为什么需要这些新类别? 的神只是为了混淆我们只是凡人?
我猜这个文件可能不太简单:
整个屠杀始于移动语义。一旦我们有可以移动和不被复制的表达式,突然很容易掌握规则要求区分可以移动的表达式和在哪个方向。
从我猜基于草案,r / l值的区别保持不变,只有在移动的东西变得凌乱的背景下。
是否需要?如果我们希望没收新的功能,可能不是。但是为了让更好的优化,我们应该可以拥抱他们。
引用:
- lvalue (所谓历史上,
,因为左值可能出现在作业
表达式的
左侧)指定一个函数或
一个对象。 [示例:如果E
是指针类型的
表达式,则* E
是一个引用
的一个左值表达式,其中E
指向的对象或函数。另一个例子,调用
返回类型的函数是一个左值引用的
结果是
一个左值。] - xvalue (一个
eXpiring值)也指一个
对象,通常在
生命周期结束之前(因此它的资源可能为
例如移动)。 xvalue是
某些类型的
表达式的结果,涉及rvalue
引用。 [示例:调用
返回类型为rvalue引用的函数的
结果为
an xvalue。] - glvalue (generalizedlvalue)是 lvalue
或 xvalue 。 - rvalue (所谓的
在历史上是因为r
出现在$ b $的右侧b赋值表达式)是一个x值,
a临时对象或
子对象,或
的值与对象无关。 - A
prvalue (purervalue)是不是xvalue的rvalue
。 [示例:调用
返回类型不是引用的函数的
结果是
prvalue]
该问题的文档是对这个问题的一个很好的参考,因为它显示了由于引入新命名而发生的标准的确切变化。 >
In C++03, an expression is either an rvalue or an lvalue.
In C++11, an expression can be an:
- rvalue
- lvalue
- xvalue
- glvalue
- prvalue
Two categories have become five categories.
- What are these new categories of expressions?
- How do these new categories relate to the existing rvalue and lvalue categories?
- Are the rvalue and lvalue categories in C++0x the same as they are in C++03?
- Why are these new categories needed? Are the WG21 gods just trying to confuse us mere mortals?
I guess this document might serve as a not so short introduction : n3055
The whole massacre began with the move semantics. Once we have expressions that can be moved and not copied, suddenly easy to grasp rules demanded distinction between expressions that can be moved, and in which direction.
From what I guess based on the draft, the r/l value distinction stays the same, only in the context of moving things get messy.
Are they needed? Probably not if we wish to forfeit the new features. But to allow better optimization we should probably embrace them.
Quoting n3055:
- An lvalue (so-called, historically,because lvalues could appear on theleft-hand side of an assignmentexpression) designates a function oran object. [Example: If
E
is anexpression of pointer type, then*E
is an lvalue expression referring tothe object or function to whichE
points. As another example, theresult of calling a function whosereturn type is an lvalue reference isan lvalue.] - An xvalue (an"eXpiring" value) also refers to anobject, usually near the end of itslifetime (so that its resources maybe moved, for example). An xvalue isthe result of certain kinds ofexpressions involving rvaluereferences. [Example: Theresult of calling a function whosereturn type is an rvalue reference isan xvalue.]
- A glvalue ("generalized" lvalue) is an lvalueor an xvalue.
- An rvalue (so-called,historically, because rvalues couldappear on the right-hand side of anassignment expression) is an xvalue,a temporary object orsubobject thereof, or a value that isnot associated with an object.
- Aprvalue ("pure" rvalue) is an rvaluethat is not an xvalue. [Example: Theresult of calling a function whosereturn type is not a reference is aprvalue]
The document in question is a great reference for this question, because it shows the exact changes in the standard that have happened as a result of the introduction of the new nomenclature.
这篇关于价值,价值,价值,价值和价值是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!