Closed Finii closed 1 year ago
If num_elements < 1
the container is empty, right? And idx
can not become negative? Then we could just return begin()
without adding + idx
, i guess. Since you can not add an element before an non-existing first element, right?
If
num_elements < 1
the container is empty, right? Andidx
can not become negative? Then we could just returnbegin()
without adding+ idx
, i guess. Since you can not add an element before an non-existing first element, right?
num_elements
is the number of elements you want to add.
The begin() + idx
dance is to 'unconst' the pos
iterator that we need to pass on :roll_eyes:
(I never liked the interface that mixes indices and iterators ;)
What I find smelly is this
const auto idx = static_cast<SizeType>(pos - begin());
pos
is a const iterator, so I would use cbegin()
, but that is another (possible) PR.
Oh you merged. I also do not really like this change and wanted to research into some better solutions, but then, would probably never have time for that :grimacing:
[why] When compiled with
-O3
(aka Meson optionoptimization=3
) GCC 12.2 optimizes too good:[how] This is the case when we add zero elements from some iterator-like source. We pass that two iterators on unchecked and finally want to memmove the elements but there are none.
Now we just check if there is something to actually insert and bail out if not.
Fixes: #22