Open
Description
The idea is this:
- Fill the buffer up to capacity at the end (needs a
revert_insert
protection). - Create a temporary buffer with the remaining elements (can throw).
- If temporary buffer is not empty
- Allocate new buffer with necessary size (can throw).
- Relocate elements
- first original elements, up to insertion point,
- then new elements (at the end of the original buffer),
- then new elements from the temporary buffer,
- then remaining old elements.
- If the temporary buffer is empty, rotate elements in the original buffer instead.
In the end result:
- If the original capacity could accommodate the input range, then no new buffer (even a temporary one) is allocated. This is particularly useful when the caller uses input iterators, but does know the input range size, and thus can call
reserve
. - We should be able to keep the strong guarantee.