June 2025
Intermediate to advanced
1093 pages
33h 24m
English
All functions from <algorithm> use assignment with E& operator=(const E&) when moving elements. With move_iterator, you can make an algorithm use the move assignment E& operator=(E&&) instead. But in both cases, an object must already exist at the destination. That means you need to initialize the entire target range with valid objects first. This can be cumbersome and unnecessary as you know that copy will overwrite the entire range anyway.
In the <memory> header, there are a handful of additional algorithms that do not require a valid object at the destination. The objects are then created with the copy constructor E(const E&) in uninitialized memory, not overwritten. ...
Read now
Unlock full access