Questions tagged [xvalue]

"xvalue" is a C++11 term for an expiring value that can be moved from

From the proposed C++11 standard:

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 ]

60 questions
30
votes
4 answers

What expressions create xvalues?

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…
PermanentGuest
  • 5,213
  • 2
  • 27
  • 36
15
votes
1 answer

What does it mean "xvalue has identity"?

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…
geza
  • 28,403
  • 6
  • 61
  • 135
14
votes
5 answers

What is decltype(0 + 0)?

(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…
Fred Nurk
  • 13,952
  • 4
  • 37
  • 63
14
votes
1 answer

Why rvalue reference binding to xvalue doesn't work in my code?

I tried to understand lvalue and rvalue in C++11. So I wrote a test code: int x = 10; int foo() { return x; } int& bar() { return x; } int&& baz() { return 10; } int main() { int& lr1 = 10; // error: lvalue references rvalue int& lr2 =…
Seokmin Hong
  • 612
  • 1
  • 5
  • 15
12
votes
2 answers

Automatic xvalue optimization

Somewhat surprisingly (to me), the following two programs compile to different outputs, with the latter one having much better performance (tested with gcc and clang): #include int main() { std::vector a(2<<20); for(std::size_t…
Xoph
  • 459
  • 2
  • 10
11
votes
1 answer

Validity of presenting an xvalue as an lvalue

The following function (in my intention) is to take an rvalue and present it as it was an lvalue. auto constexpr RtoL = [](auto&& r) -> decltype(auto) { static_assert(std::is_rvalue_reference_v, "Gimme rvalues, not lvalues."); …
Enlico
  • 23,259
  • 6
  • 48
  • 102
10
votes
2 answers

xvalues: differences between non class types and class types

Consider the minimal example below: #include struct S { }; int main() { S s; std::move(s) = S{}; } It compiles with no errors. If I use non class types instead, I get an error. As an example, the code below doesn't…
skypjack
  • 49,335
  • 19
  • 95
  • 187
9
votes
2 answers

In C++, what categories (lvalue, rvalue, xvalue, etc.) can expressions that produce temporaries of class type fall into?

Here is some example code: #include class Foo { public: explicit Foo(int x) : data(x) {}; Foo& operator++() { data += 1; return *this; } void *get_addr() { return (void*)this; } friend Foo operator + (const…
CppNoob
  • 2,322
  • 1
  • 24
  • 35
9
votes
1 answer

where and when an xvalue is used?

I read the standard on xvalue. It is closely associated with rvalue reference expression. But when programming, I really cannot find scenarios that needs xvalue. For example: function myClass&& f() return an rvalue reference. So expression f() is…
Zachary
  • 1,633
  • 2
  • 22
  • 34
8
votes
1 answer

Are temporary objects xvalues?

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…
khaos
  • 632
  • 3
  • 11
8
votes
2 answers

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

If I write the following code: #include 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…
FatalError
  • 52,695
  • 14
  • 99
  • 116
7
votes
2 answers

Lifetime extension, prvalues and xvalues

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…
Curious
  • 20,870
  • 8
  • 61
  • 146
6
votes
1 answer

Is this expression an xvalue?

The C++ standard says the following about 'xvalues' (N4762 § 7.2.1.4): An expression is an xvalue if it is: - . . . - a class member access expression designating a non-static data member of non-reference type in which the object…
Tootsie
  • 655
  • 3
  • 11
6
votes
2 answers

xvalues vs prvalues: what does identity property add

I'm sorry for the broadness of the question, it's just that all these details are tightly interconnected.. I've been trying to understand the difference between specifically two value categories - xvalues and prvalues, but still I'm…
ledonter
  • 1,269
  • 9
  • 27
6
votes
1 answer

Find X-value position of a label inside a view in Swift

I want to calculate the distance between x-value of two squares positioned in a view. I did not work because in the frame there is also the y-value and do not know how to select only one. how can I add the x-values from the position of the…
Antonio Viscomi
  • 227
  • 2
  • 5
  • 15
1
2 3 4