Details
-
Epic
-
Resolution: Unresolved
-
P2: Important
-
None
-
None
-
None
-
detach-remove
Description
In almost all remove-like operations, our containers first detach and then do the remove. This is inefficient, because we spend time copying elements we may not want in the final result.
If *this is shared, then we should not detach. Instead, we should make a new container, and copy only those that would have been kept.
iow, in pseudo-STL:
- auto copy = c; - remove(copy, x); + decltype(c) copy; + remove_copy(c, copy, x);
A similar argument can be made for operations that grow the container, like insert().