gpt4 book ai didi

c++ - C++ 中的 xvalue 是什么

转载 作者:行者123 更新时间:2023-12-02 00:54:09 24 4
gpt4 key购买 nike

我试图了解值(value)类别的差异,我发现 this document由微软开发。

enter image description here

- An xvalue is a glvalue that [...]
- An lvalue is a glvalue that is not an xvalue.
- An rvalue is a prvalue or an xvalue.

为什么xvalueglvalue?他们为什么不说xvalue是左值或右值?在我看来,这个措辞是有意传达某种信息,但我不明白为什么

最佳答案

Why didn't they say An xvalue is an glvalue or an rvalue?

因为右值尚未定义,并且右值将根据 xvalue 定义。必须在不依赖另一个的情况下定义一个,以避免定义变得循环。

还因为 xvalue 既是左值又是右值。

此外,xvalue 是左值,但不是左值。更进一步,xvalue 是一个右值,而不是纯右值。最后,xvalue 是一个既不是左值也不是纯右值的表达式。

I don't understand why they only mentioned gvalues in that sentence

仅定义了左值和右值。请参阅前面提到的避免循环定义。

What are xvalues in C++

好吧,您已经看到了它的定义。该标准有以下非规范性注释,提供了更多信息:

[basic.lval]

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

  • the result of calling a function, whether implicitly or explicitly, whose return type is an rvalue reference to object type ([expr.call]),
  • a cast to an rvalue reference to object type ([expr.type.conv], [expr.dynamic.cast], [expr.static.cast] [expr.reinterpret.cast], [expr.const.cast], [expr.cast]),
  • a subscripting operation with an xvalue array operand ([expr.sub]),
  • a class member access expression designating a non-static data member of non-reference type in which the object expression is an xvalue ([expr.ref]), or
  • a .* pointer-to-member expression in which the first operand is an xvalue and the second operand is a pointer to data member ([expr.mptr.oper]).

关于c++ - C++ 中的 xvalue 是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58703140/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com