C++0x新概念:glvalue, xvalue, prvalue(泛左值,x值,纯右值)

以下内容摘自最新的C++0x草案

All expressions are now divided into three "value categories":

* "lvalues" are the same as what's meant traditionally by lvalue.
* "xvalues" are objects created by rvalue reference operations (sometimes previously called "rvalue reference objects"). The "x" can be for "eXpiring value" or a cross between lvalues and rvalues.
* "prvalues" are the new name for traditional rvalues (i.e., excluding the xvalue cases). The "p" is for "pure rvalue".

There are two compound categories:

* "glvalues" are lvalues and xvalues. These are things that have dynamic type and object identity.
* "rvalues" are xvalues and prvalues. These are (as now in the draft) things that are potentially movable.

... named rvalue references are treated as lvalues and unnamed rvalue references to objects are treated as xvalues; rvalue references to functions are treated as lvalues whether named or not.

 表达式根据其值的类型可分为以下三类:

  • lvalue:左值,即传统意义上的左值。
  • xvalue(expiring value):x值(中间值?),指通过“右值引用”产生的对象。
                                     这里x可以理解为即将消失(expiring),也可理解为中间(横跨左值和右值)。
  • prvalue(pure rvalue):纯右值,即传统意义上的右值。
两种复合类型:
  • glvalue(general lvalue):泛左值,由左值和x值构成。泛左值具有动态的类型和对象属性。
  • rvalue:右值,由x值和纯右值构成。右值具有潜在的可移动性。
关于右值引用:
  • 具名右值引用被视为左值。
  • 无名右值引用被视为x值。
  • 对函数的右值引用无论具名与否都将被视为左值。
struct A {
  int m;
};
A&& operator+(A, A);
A&& f();
A a;
A&& ar = static_cast<A&&>(a);
这里表达式 f(), f().m, static_cast<A&&>(a), 以及 a + a 都是 x值。
而表达式 ar 为 A 类型的左值。
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值