One of my function I'm inserting an arbitrary number of new elements into a vector at a given index. Because every insertion need to shift all the elements after the index, it is rather slow. Because of that I created an other vector, and tried to insert that at once. The problem is there is no such function implemented on the vector type, and I also can't use array/slice methods like firstvec[..index].concat(othervec).concat(firstvec[index+1..]);
or [[firstvec[..index], othervec, firstvec[index+1..]].join()
since these are only seem to work with constant sized arrays. Is there a way to insert my vector into the other, or to concentrate the slices?
Asked
Active
Viewed 22 times
0

SurGe
- 23
- 3
-
Sadly it isn't, I already found this one, but these methods are overwrite a range in a vector, while I want to insert new elements, while keeping all the old one, so the vector's size are increasing. – SurGe Jun 20 '22 at 21:09
-
@SurGe This question and answer are also explicitly about insertion (the answer even gives an example). If you splice into en empty range, you're effectively inserting. – Chayim Friedman Jun 20 '22 at 21:12
-
My bad, I checked it quickly and thought it is an other question I previously seen. I'm so sorry and thank you, so much! – SurGe Jun 20 '22 at 21:25