customized vector: o(1) deletion

Is it somewhere implemented customized vectior container with o(1) deletion operation and invalidation of only of last and end iterators?
Last edited on
std::swap( container.back(), *iterator );
container.pop_back()

is a solution
In this situation I think it's better to move the object instead of using swap.

1
2
*iterator = std::move(container.back());
container.pop_back();
In C++11, std::swap already takes advantage of move semantics. resize is probably more appropriate than pop_back, though. Do we really want to generate a copy if we're worried about performance?
In C++11, std::swap already takes advantage of move semantics.

Yes, but swap might do more work because it will move a value to the soon-to-be-popped last element.
Do we really want to generate a copy if we're worried about performance?
The STL pop*() functions are named somewhat wrong, since they don't return anything. pop_back() is equivalent to resize(size() - 1).
I've been spending too much time with Python lately, I guess. ;)
Topic archived. No new replies allowed.