什么是右值,左值,x值,glvalues和prvalues? [英] What are rvalues, lvalues, xvalues, glvalues, and prvalues?

查看:325
本文介绍了什么是右值,左值,x值,glvalues和prvalues?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C ++ 03中,表达式为 rvalue lvalue

In C++03, an expression is either an rvalue or an lvalue.

++ 11,表达式可以是:

In C++11, an expression can be an:


  1. rvalue

  2. 左值
  3. xvalue

  4. glvalue >
  5. prvalue

  1. rvalue
  2. lvalue
  3. xvalue
  4. glvalue
  5. prvalue

两个类别已成为五个类别。

Two categories have become five categories.


  • 这些新类别的表达式是什么?

  • 这些新类别如何与现有的右值和左值类别?

  • C ++ 0x中的右值和左值类别是否与C ++ 03中的相同?

  • 为什么需要这些新类别? WG21 神只是试图混淆我们的纯粹的凡人吗?

  • 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?

推荐答案

我猜这个文档可能不是那么简短的介绍:n3055

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.

从我猜测基于草案,r / l值的区别保持不变,只有在移动的东西变得凌乱的上下文中。

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.

引用n3055

Quoting n3055:


  • lvalue (所谓的,历史上为
    ,因为lvalue可能出现在
    左侧的赋值
    表达式)指定一个函数或
    一个对象。 [示例:如果 E 是指针类型的
    表达式,则 * E
    是一个指向
    的左值表达式 E
    指向的对象或函数。作为另一个例子,调用其
    返回类型是一个左值引用的函数的
    结果是
    一个左值。]

  • xvalue (一个
    eXpiring值)也指一个
    对象,通常接近其
    生命周期的结尾(因此其资源可能为
    例如,移动)。 xvalue是
    某些种类的
    表达式的结果,涉及rvalue
    引用。
    > glvalue (广义左值)是左值
    xvalue

  • 右值(所谓的
    历史上,因为右值可能
    出现在$ b $的右侧b赋值表达式)是一个xvalue,
    a临时对象或
    子对象,或者一个值
    不与一个对象相关联的值。

  • A
    prvalue (纯值右值)是一个右值
    ,不是xvalue。
  • 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.]
  • 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. [Example: The result of calling a function whose return type is an rvalue reference is an xvalue.]
  • A glvalue ("generalized" lvalue) is an lvalue or an 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 or subobject thereof, or a value that is not associated with an object.
  • 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 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.

这篇关于什么是右值,左值,x值,glvalues和prvalues?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆