3.10 左值和右值 中英文对照(C++标准中文版 ISO/IEC 14882:2014)

3.10 Lvalues and rvalues [basic.lval]
3.10 左值和右值


1 Expressions are categorized according to the taxonomy in Figure 1.

1 表达式根据图1的分类系统被归类:

             expression
              /      \
         glvalue     rvalue
         /     \    /     \
      lvalue   xvalue    prvalue
Figure 1 — Expression category taxonomy
图1-表达式分类系统

— An lvalue (so called, historically, because lvalues could appear on the left-hand side of an assignment expression) designates a function or an object. [Example: If E is an expression of pointer type, then *E is an lvalue expression referring to the object or function to which E points. As another example, the result of calling a function whose return type is an lvalue reference is an lvalue. —end example ]
— lvalue(左值,这么叫的历史原因,是因为它可以出现在赋值表达式的左手边)指代函数或对象。[例:如果E为指针类型的表达式,那么*E是一个左值表达式,指代E所指向的对象或函数。作为另一个例子,对于返回类型为左值引用的函数,其调用结果是一个左值。—例结束]

— An xvalue (an “eXpiring” value) also refers to an object, usually near the end of its lifetime (so that its resources may be moved, for example). An xvalue is the result of certain kinds of expressions involving rvalue references (8.3.2). [Example: The result of calling a function whose return type is an rvalue reference is an xvalue. —end example ]
— xvalue(“到期”值)同样指代一个对象,通常接近其生命周期结束时(由此,其资源可被移动,例如)。xvalue是特定种类表达式的结果,这些表达式涉及右值引用(8.3.2)。[例:对于返回类型是右值引用的函数,其调用结果是一个xvalue。—例结束]

— A glvalue (“generalized” lvalue) is an lvalue or an xvalue.
— glvalue(“泛化”左值)是lvalue或xvalue。

— An rvalue (so called, historically, because rvalues could appear on the right-hand side of an assignment expression) is an xvalue, a temporary object (12.2) or subobject thereof, or a value that is not associated with an object.
— rvalue(右值,这么叫的历史原因,是因为它可以出现在赋值表达式的右手边)是xvalue,临时对象(12.2)或其子对象,或是一个没关联到对象的值。

— A prvalue (“pure” rvalue) is an rvalue that is not an xvalue. [Example: The result of calling a function whose return type is not a reference is a prvalue. The value of a literal such as 12, 7.3e5, or true is also a prvalue. —end example ]
— prvalue(“纯”右值)是除xvalue之外的右值。[例:对于返回类型非引用的函数,其调用结果是一个纯右值。对于字面量,像12、7.3e5或true,其值也是纯右值。—例结束]

Every expression belongs to exactly one of the fundamental classifications in this taxonomy: lvalue,
xvalue, or prvalue. This property of an expression is called its value category. [Note: The discussion of each built-in operator in Clause 5 indicates the category of the value it yields and the value categories of the operands it expects. For example, the built-in assignment operators expect that the left operand is an lvalue and that the right operand is a prvalue and yield an lvalue as the result. User-defined operators are functions, and the categories of values they expect and yield are determined by their parameter and return types. —end note ]

在此分类系统中,每个表达式都确切归为基本分类之一:左值、到期值或纯右值。表达式的这种属性被称为它的值类别。[注:条款5对每个内建操作符的讨论中,指明了它所产生值的类别,以及它期待的操作数的值类别。比如,内建赋值操作符期待的左操作数是一个左值,且右操作数是一个纯右值,并产生一个左值作为结果。用户定义的操作符是函数,它们期待并产生的值的类别,由其形参和返回类型所决定。— 注结束]

2 Whenever a glvalue appears in a context where a prvalue is expected, the glvalue is converted to a prvalue; see 4.1, 4.2, and 4.3. [Note: An attempt to bind an rvalue reference to an lvalue is not such a context; see 8.5.3. —end note ]
2 当出现在期待纯右值的上下文中时,泛化左值被转换为纯右值;见4.1,4.2以及4.3。[注:试图将右值引用绑定到左值的情况,不属于前述的上下文;见8.5.3。— 注结束]

3 The discussion of reference initialization in 8.5.3 and of temporaries in 12.2 indicates the behavior of lvalues and rvalues in other significant contexts.
3 在8.5.3中讨论的的引用初始化,以及12.2中讨论的临时变量,指出了其他值得注意的上下文,此时左值和右值有着不同行为。

4 Unless otherwise indicated (5.2.2), prvalues shall always have complete types or the void type; in addition to these types, glvalues can also have incomplete types. [Note: class and array prvalues can have cv-qualified types; other prvalues always have cv-unqualified types. See Clause 5. —end note ]
4 除非另有指示(5.2.2),纯右值应该总是具有完整类型或void类型;除了这些类型之外,泛化左值还可以是不完整类型。[注:clas和数组纯右值可以有cv限定类型;其他纯右值总有cv非限定类型。见条款5. —注结束](译者注:C++11数组右值不能有cv限定类型)
 
5 An lvalue for an object is necessary in order to modify the object except that an rvalue of class type can also be used to modify its referent under certain circumstances. [Example: a member function called for an object (9.3) can modify the object. —end example ]
5 有必要为对象提供一个左值,以便修改该对象,除了class类型的右值在特定情况下也能被用来修改其引用。[例:为一个对象所调用的成员函数(9.3)可以修改该对象。—例结束](译者注:译者未能参透本段落,请参阅英文)

6 Functions cannot be modified, but pointers to functions can be modifiable.
6 函数不可被修改,但是指向函数的指针可被修改。

7 A pointer to an incomplete type can be modifiable. At some point in the program when the pointed to type is complete, the object at which the pointer points can also be modified.
7 指向不完整类型的指针可以是可修改的。在程序某处,当所指类型完整时,该指针所指的对象能同样被修改。

8 The referent of a const-qualified expression shall not be modified (through that expression), except that if it is of class type and has a mutable component, that component can be modified (7.1.6.1).
8 对于const限定的表达式,其引用不应该被修改(通过那个表达式),除非它是class类型,且具有mutable成员,该成员可被修改(7.1.6.1)。

9 If an expression can be used to modify the object to which it refers, the expression is called modifiable. A program that attempts to modify an object through a nonmodifiable lvalue or rvalue expression is ill-formed.

9 如果一个表达式可被用来修改它所指代的对象,该表达式称为可被修改的。企图通过不可被修改的左值或右值表达式来修改对象,是不良形式的程序。

10 If a program attempts to access the stored value of an object through a glvalue of other than one of the following types the behavior is undefined: [54 The intent of this list is to specify those circumstances in which an object may or may not be aliased.]
10 若程序试图用不属于下述描述的glvalue来访问对象所存储的值,那么行为是未定义的[注54:这个列表的意图在于,指定在哪些情况下一个对象可以或不可被别名化]:

— the dynamic type of the object,
— 对象的动态类型,
— a cv-qualified version of the dynamic type of the object,
— 对象动态类型的cv限定版本,
— a type similar (as defined in 4.4) to the dynamic type of the object,
— 一个类似于对象动态类型的类型(如4.4中的定义),
— a type that is the signed or unsigned type corresponding to the dynamic type of the object,
— 相应于对象动态类型的带符号或无符号类型,
— a type that is the signed or unsigned type corresponding to a cv-qualified version of the dynamic type of the object,
— 相应于对象动态类型之cv限定版本的带符号或无符号类型,
— an aggregate or union type that includes one of the aforementioned types among its elements or non-static data members (including, recursively, an element or non-static data member of a subaggregate or contained union),
— 包含前述类型之一的聚合或union类型,在其元素或非静态数据成员之间(包括,递归地,属于子聚合或被包含的union的元素或非静态数据成员),(译者注:译者未能参透本段落,请参阅英文)
— a type that is a (possibly cv-qualified) base class type of the dynamic type of the object,
— 对象动态类型的基类类型(可能被cv限定),
— a char or unsigned char type.
— char或unsigned char类型。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值