There are several scenarios in which C++11’s move semantics do us no good:
- No move operations: the object to be moved from fails to offer move operations. The move request thus becomes a copy request
- Move not faster: the object to be moved from has move operations that are no faster than its copy operations1
- Move not usable: the context in which the moving would take place requires a move operation that emits no exceptions, but that operation isn’t declared
noexcept
- Source object is lvalue: with very few exceptions (e.g., item 25), only rvlaues may be used as the source of a move operation
-
For example,
std::vector
, conceptually, holds only a pointer to the heap memory storing the contents of the container, so it is possible to move the contents of an entire container in constant time; however, forstd::array
, the data is stored directly in thestd::array
object, so the move operation runs in linear time. Similar analysis applies tostd::string
when the small string optimization (SSO) occcurs. ↩︎