...
In this compliant solution, pos
is assigned a valid iterator on each insertion, removing the preventing undefined behavior:
Code Block | ||||
---|---|---|---|---|
| ||||
#include <deque> void f(const double *items, std::size_t count) { std::deque<double> d; auto pos = d.begin(); for (std::size_t i = 0; i < count; ++i, ++pos) { pos = d.insert(pos, items[i] + 41.0); } } |
...