GLVALUE真正的例子和解释? [英] Glvalue real examples and explanation?

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

问题描述

我知道"xvalues","prvalues","rvalues"和"lvalues"是什么,它们有什么帮助,我已经看到了它们的真实示例.但是我从来不了解什么是"glvalue",以及它如何与其他人合作.我到处搜索过,但运气不好,即使在最新的标准论文中也很少有人注意到.有人可以向我解释一下并显示一些示例吗?

I know what 'xvalues', 'prvalues', 'rvalues' and 'lvalues' are, how they are helpful and I've seen real examples of them. But I've never understand what a 'glvalue' is, and how it co-operate with the others. I've searched everywhere but with no-luck even in the latest standard paper it was barely noticed. Can somebody explains it to me and show some examples?

请注意,这不是的重复项,即使在那儿也没有人举"glvalue"的例子.此处也是.像这样几乎没有被提及:

Note that this is not a duplicate of this, as even there nobody gave an example of 'glvalue'. Here too. It was only barely mentioned like this:

glvalue(广义"左值)是左值或x值.

A glvalue ("generalized" lvalue) is an lvalue or an xvalue.

推荐答案

glvalue是不是prvalue的任何东西.例如实体名称或具有引用类型(无论引用的类型如何)的表达式.

A glvalue is anything that isn't a prvalue. Examples are names of entities, or expressions that have reference type (regardless of the kind of the reference).

int i;
int* p = &i;
int& f();
int&& g();

int h();

h() // prvalue
g() // glvalue (xvalue)
f() // glvalue (lvalue)
i   // glvalue (lvalue)
*p  // glvalue (lvalue)

std::move(i)  // glvalue (xvalue)

问题中的引号明确指出,类别 glvalue 包括所有xvalues和lvalues.左值,右值和右值是互补的类别:

As the quote in your question clearly states, the category glvalue includes all xvalues and lvalues. lvalues, xvalues and prvalues are complementary categories:

每个表达式都完全属于基本表达式之一此分类法中的分类:左值,左值或右值.

Every expression belongs to exactly one of the fundamental classifications in this taxonomy: lvalue, xvalue, or prvalue.

您应该熟悉左值.现在考虑什么是xvalue,[expr]/6:

You should be familiar with lvalues. Now consider what xvalues are, [expr]/6:

[注意:表达式是x值,如果它是:

[ Note: An expression is an xvalue if it is:

  • 调用函数(无论是隐式还是显式)的结果,该函数的返回类型是对对象类型的右值引用,
  • 转换为对对象类型的右值引用
  • 类成员访问表达式,它指定非引用类型的非静态数据成员,其中对象表达式是一个xvalue,或
  • .* 指向成员的表达式,其中第一个操作数是x值,第二个操作数是指向数据成员的指针.
  • the result of calling a function, whether implicitly or explicitly, whose return type is an rvalue reference to object type,
  • a cast to an rvalue reference to object type,
  • a class member access expression designating a non-static data member of non-reference type in which the object expression is an xvalue, or
  • a .* pointer-to-member expression in which the first operand is an xvalue and the second operand is a pointer to data member.

[…] —尾注]

因此,粗略地说,您可以将glvalues视为
所有包含rvalue引用的lvalues和表达式".
我们用它来描述引用对象的表达式,而不是成为"这些对象.

So, roughly speaking, you could think of glvalues as
"All lvalues plus expressions involving rvalue references".
We use it to describe expressions that refer to objects rather than "being" those objects.

这篇关于GLVALUE真正的例子和解释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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