Q:

Is there a way to insert something into the middle of a vector constant time

I want to insert element i into std::vector someVector but don't want to use .insert() since it is O(n) complexity since (as far as I know) it pushes back all the other elements.
Is there anyway to do so in constant time similar to the swap/resize trick for erase?

A:

Yes, if you can accept a restriction to sequential access for the insert or delete position.
The basic idea is known as a cursor gap (because it was used in early text editors) or more generally a gap buffer structure. There is a Wikipedia article about it. But in short, you just maintain a sequence or “gap” of all unused items where you have the insert/delete position, and moving the insert/delete position one step corresponds to copying a real item from one side to the other side of the gap.
Indexing with contiguous range of indices is still constant time with a gap in the middle (you just have to define it properly), but in order to then use the vector's buffer directly as a contiguous array, the gap has to be moved to one side, which is a linear time operation.

