xvalue

Lifetime extension, prvalues and xvalues

纵饮孤独 提交于 2020-01-21 05:37:25
问题 Following the well accepted answer to this question Do rvalue references allow dangling references? It would seem that xvalues do not have their lifetime extended when assigned to a rvalue reference lvalue like in the question. However when I do this #include <iostream> using namespace std; class Something { public: Something() { cout << "Something()" << endl; } Something(const Something&) { cout << "Something(const Something&)" << endl; } Something(Something&&) { cout << "Something(Something

What is decltype(0 + 0)?

我与影子孤独终老i 提交于 2020-01-11 08:05:08
问题 (Prompted by an answer.) Given N3290, §7.1.6.2p4, where the list items are unnumbered, but numbered here for our convenience: The type denoted by decltype(e) is defined as follows: if e is an unparenthesized id-expression or an unparenthesized class member access (5.2.5), decltype(e) is the type of the entity named by e. If there is no such entity, or if e names a set of overloaded functions, the program is ill-formed; otherwise, if e is an xvalue, decltype(e) is T&&, where T is the type of e

What is decltype(0 + 0)?

和自甴很熟 提交于 2020-01-11 08:05:07
问题 (Prompted by an answer.) Given N3290, §7.1.6.2p4, where the list items are unnumbered, but numbered here for our convenience: The type denoted by decltype(e) is defined as follows: if e is an unparenthesized id-expression or an unparenthesized class member access (5.2.5), decltype(e) is the type of the entity named by e. If there is no such entity, or if e names a set of overloaded functions, the program is ill-formed; otherwise, if e is an xvalue, decltype(e) is T&&, where T is the type of e

Is an xvalue's lifetime extended when it is bound to a const lvalue reference?

旧时模样 提交于 2019-12-30 08:25:10
问题 If I write the following code: #include <iostream> using namespace std; int main() { cout << &(int &&)123 << endl; return 0; } Then g++ complains: foo.cc: In function ‘int main()’: foo.cc:7:20: error: taking address of xvalue (rvalue reference) Ok, thanks to What are rvalues, lvalues, xvalues, glvalues, and prvalues? I get that an xvalue means that it's about to "expire", which makes sense. But now if I do this: #include <iostream> using namespace std; int main() { const int &x = (int &&)123;

Are temporary objects xvalues?

不想你离开。 提交于 2019-12-07 00:21:26
问题 I am currently writing my degree dissertation and it involves also some explaining of the theory behind C++11 which is really fine as C++ is my programming language of choice and the standard is more or less available for free (N3337) to get yourself lost in. Yet I have hit a wall while trying to explain the new xvalue category accurately and in detail. It is my understanding that a temporary object is always a xvalue but I cannot find any reference to this in the standard. It is my

What does it mean “xvalue has identity”?

一笑奈何 提交于 2019-12-05 23:31:44
问题 C++11 introduced new value categories, one of them is xvalue . It is explained by Stroustrup as something like ( im category): "it is a value, which has identity, but can be moved from". Another source, cppreference explains: a glvalue is an expression whose evaluation determines the identity of an object, bit-field, or function; And xvalue is a glvalue , so this is statement is true for xvalue too. Now, I thought that if an xvalue has identity, then I can check if two xvalue s refer to the

What does it mean “xvalue has identity”?

依然范特西╮ 提交于 2019-12-04 05:02:07
C++11 introduced new value categories, one of them is xvalue . It is explained by Stroustrup as something like ( im category): "it is a value, which has identity, but can be moved from". Another source, cppreference explains: a glvalue is an expression whose evaluation determines the identity of an object, bit-field, or function; And xvalue is a glvalue , so this is statement is true for xvalue too. Now, I thought that if an xvalue has identity, then I can check if two xvalue s refer to the same object, so I take the address of an xvalue . As it turned out, it is not allowed: int main() { int

What is decltype(0 + 0)?

落花浮王杯 提交于 2019-12-01 15:14:42
(Prompted by an answer .) Given N3290, §7.1.6.2p4, where the list items are unnumbered, but numbered here for our convenience: The type denoted by decltype(e) is defined as follows: if e is an unparenthesized id-expression or an unparenthesized class member access (5.2.5), decltype(e) is the type of the entity named by e. If there is no such entity, or if e names a set of overloaded functions, the program is ill-formed; otherwise, if e is an xvalue, decltype(e) is T&&, where T is the type of e; otherwise, if e is an lvalue, decltype(e) is T&, where T is the type of e; otherwise, decltype(e) is

Is an xvalue's lifetime extended when it is bound to a const lvalue reference?

瘦欲@ 提交于 2019-12-01 03:50:18
If I write the following code: #include <iostream> using namespace std; int main() { cout << &(int &&)123 << endl; return 0; } Then g++ complains: foo.cc: In function ‘int main()’: foo.cc:7:20: error: taking address of xvalue (rvalue reference) Ok, thanks to What are rvalues, lvalues, xvalues, glvalues, and prvalues? I get that an xvalue means that it's about to "expire", which makes sense. But now if I do this: #include <iostream> using namespace std; int main() { const int &x = (int &&)123; cout << &x << endl; return 0; } This "works" just fine and will print an address. So, I have a few

What expressions create xvalues?

不打扰是莪最后的温柔 提交于 2019-11-26 23:01:04
问题 I'm trying to understand the C++11 concepts. The standard draft which I have says: 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 (8.3.2). [ Example: The result of calling a function whose return type is an rvalue reference is an xvalue. —end example ] OK, so what exactly are the "certain kinds of expressions"