2

I am trying to better understand the std::move(). I used to think it creates a cast to an rvalue reference. But in the documentation I have come across this:

std::move produces an xvalue expression that identifies its argument. It is exactly equivalent to a static_cast to an rvalue reference type.

It is unclear for me, why there exist xvalue's alongside with rvalue's? Is it a matter of the C++11 vs. C++14 standard?

igor
  • 131
  • 1
  • 7
  • 2
    [See here](http://stackoverflow.com/questions/3601602/what-are-rvalues-lvalues-xvalues-glvalues-and-prvalues?rq=1) – M.M Apr 25 '16 at 23:29
  • 1
    1) An xvalue *is* an rvalue. Rvalue is a more general concept. 2) You cannot "cast to a reference", since a cast is an expression, and the type of an expression is always an object type (or void), never a reference. You can, however, cast to lvalue, xvalue or prvalue (by specifying an appropriate type in the cast). – Kerrek SB Apr 25 '16 at 23:29
  • 1
    Simple example: for respectively `T f();`, `T& f()` and `T&& f();`, `decltype(f())` is `T`, `T&` and `T&&`. In other words, these are examples of functions returning, respectively, prvalues, lvalues and xvalues, and the result of the call expression `f()` is a value of the respective category (and of type `T`). – Kerrek SB Apr 25 '16 at 23:30

0 Answers0