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

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

问题描述

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



在C ++ 11,表达式可以是:


  1. rvalue

  2. 左值

  3. xvalue

  4. glvalue

  5. prvalue

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


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

  • 这些新类别与现有的rvalue和lvalue类别?

  • C ++ 0x中的rvalue和lvalue类别是否与C ++ 03中相同?

  • 为什么需要这些新类别? WG21 的神只是为了混淆我们只是凡人?


解决方案

我猜这个文件可能不太简单: n3055



整个屠杀始于移动语义。一旦我们有可以移动和不被复制的表达式,突然很容易掌握规则要求区分可以移动的表达式和在哪个方向。



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



是否需要?如果我们希望没收新的功能,可能不是。但是为了让更好的优化,我们应该可以拥抱他们。



引用 n3055




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

  • xvalue (一个
    eXpiring值)也指一个
    对象,通常在
    生命周期结束之前(因此它的资源可能为
    例如移动)。 xvalue是
    某些类型的
    表达式的结果,涉及rvalue
    引用。 [示例:调用
    返回类型为rvalue引用的函数的
    结果为
    an x​​value。]

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

  1. rvalue
  2. lvalue
  3. xvalue
  4. glvalue
  5. 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 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.

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

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