Item 29 from Effective Modern C++, Scott Meyers lists three scenarios where move semantics don't improve code's performance,
- No move operations: The object to be moved from fails to offer move operations […]
- Move not faster: […] move operations that are no faster than its copy operations.
- Move not usable: The context […] requires a move operation that emits no exceptions, but that operation isn't declared
noexcept
.
which are all clearly explained in the preceding pages, and then adds another one
- Source object is lvalue: With very few exceptions (see e.g. Item 25) only rvalues may be used as the source of a move operation.
After this, the text essentially goes back to summarizing the item, with no further reference to that fourth bullet point.
What does that bullet point refer to?
As far as I understand move semantics, even if I want to move from an lvalue, say x
, I still need to cast it to an rvalue via std::move(x)
(or an equivalent static_cast
), so I'm technically still moving from an rvalue (specifically an xvalue in this case), not an lvalue.
So I'd be tempted to say that an lvalue cannot be the source object of a move operation.
What am I missing about this topic?
Aucun commentaire:
Enregistrer un commentaire