- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
#include <vector>
using namespace std;
struct A
{
vector<int> coll;
};
void f(const vector<int>&){}
void f(vector<int>&&){}
int main()
{
f(A().coll); // Is "A().coll" an xvalue?
}
C++11是否保证f(A().coll)
将调用 void f(vector<int>&&)
?
最佳答案
是的。 C++14 标准,§5.2.5/4.2,给定 E1.E2
:
If
E2
is a non-static data member and the type ofE1
is “cq1 vq1 X”, and the type ofE2
is “cq2 vq2 T”, the expression designates the named member of the object designated by the first expression. IfE1
is an lvalue, thenE1.E2
is an lvalue; otherwiseE1.E2
is an xvalue.
学究式地,最初 C++11 将其归类为纯右值,但这样的分类毫无意义,因此被更改。但是,如果更改是由缺陷报告应用的,则它具有追溯力——已发布的 C++11 标准文档 N3290 是错误的,而 C++14 文档定义了 C++11。很可能是这种情况,否则将需要编译器在 -std=c++11
和 -std=c++14
之间实现细微的行为差异。我现在懒得搜索 DR。
关于c++ - 临时对象的数据成员是 C++11 中的 xvalue 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42444262/
根据我的理解,下面的代码应该调用 Test 类的 move 构造函数,因为这个函数按值返回,这意味着表达式 GetTestObj() 应该是右值,xvalues 是隐式的 move 但为什么这段代码调
所以我读了这个answer因为我对何时将值视为 xvalue 感到困惑,例如当值即将到期/接近其生命周期结束时。可悲的是,我仍然很困惑。 无论如何,引文包括: a class member acces
我阅读了关于xvalue 的标准。它与 rvalue reference 表达式密切相关。但是在编程的时候,实在找不到需要xvalue的场景。 例如:函数 myClass&& f() 返回一个 rva
从 5.2.1.1 开始: The expression E1[E2] is identical (by definition) to *((E1)+(E2)) [...] except that i
根据我对此发表的评论: passing std::vector to constructor and move semantics以下代码中是否需要std::move,以确保返回值是xvalue? s
我想知道是否有人可以讲述或解释一些 xvalues、glvalues 和 prvalues 的现实生活示例?我读过一个类似的问题: What are rvalues, lvalues, xvalues
我正在尝试理解 C++11 的概念。 我所说的标准草案: An xvalue (an “eXpiring” value) also refers to an object, usually near
here弄清楚 “具有身份”:地址,一个指针,用户可以判断两个拷贝是否相同。 xvalue:具有标识并且可以从中移动(例如将左值转换为右值引用的结果。 here弄清楚 以下表达式是 xvalue 表达
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: What constitutes a valid state for a “moved from” obje
假设我们有一个函数: struct A { int m; }; A&& f(); 据我所知的表达方式: f(); f().m; 都是xvalue。但为什么?为什么他们不是prvalue?我有点
我们有以下类型 X 和函数 f: struct X { ... }; X f() { ... }; 现在考虑另一个函数 g 的三个替代定义: (1) void g() { X x = f();
在cpprefernce section: Value categories ,它指出“对象表达式的成员,其中 a 是右值,m 是非引用类型的非静态数据成员”是一个 xvalue。在标准中(我在:N4
根据这份文件: http://www.stroustrup.com/terminology.pdf l 值具有同一性且不可移动。 公关值是可移动的,但没有身份。 x 值具有同一性并且是可移动的。 关于
C++ 标准对“xvalues”的描述如下(N4762 § 7.2.1.4): An expression is an xvalue if it is: - . . . - a class membe
C++11 引入了新的值类别,其中之一是 xvalue . 是explained由 Stroustrup 描述为类似(im 类别):“它是一个值,具有身份,但可以从中 move ”。 另一个来源, c
我目前正在写我的学位论文,它还涉及对 C++11 背后理论的一些解释,这真的很好,因为 C++ 是我选择的编程语言,而且该标准或多或少是免费提供的 (N3337)让自己迷路。 然而,我在尝试准确详细地
我是 C++ 的新手,这是我的第一个问题,所以请多多包涵……我已经阅读左值和右值有一段时间了,我想我理解了其中的大部分内容,但仍有一些内容令人困惑我 ... 所以我的问题会很具体 右值引用被认为是左值
有点令人惊讶(对我来说),以下两个程序编译成不同的输出,后一个具有更好的性能(用 gcc 和 clang 测试): #include int main() { std::vector a(2
xvalue的定义如下: — An xvalue (an “eXpiring” value) also refers to an object, usually near the end of its
我按照教程进行操作:http://www.amcharts.com/tutorials/detecting-at-what-value-mouse-pointer-is/但我没有得到正确的值。这是代码
我是一名优秀的程序员,十分优秀!