January 2018
Intermediate to advanced
374 pages
9h 53m
English
In addition to being applied to objects, you can also add the && modifier to a member function of a class, just as you can apply a const modifier to a member function. As in the case with the const modifier, a member function which has the && modifier is only permitted to be executed on an r-value.
struct Foo { auto func() && {} }; auto a = Foo{}; a.func(); // Does not compile, 'a' is not an r-value std::move(a).func(); // Compiles Foo{}.func(); // Compiles
It might seem odd that one would ever want this behavior, but there are cases. We will investigate one of those cases in Chapter 9, Proxy Objects and Lazy Evaluation.
Read now
Unlock full access