FastLED 3.9.15
Loading...
Searching...
No Matches

◆ insert_copy_impl()

void fl::vector_basic::insert_copy_impl ( fl::size index,
const void * element )

Insert element at index by copy. Shifts subsequent elements right.

Definition at line 238 of file basic_vector.cpp.hpp.

238 {
239 if (index > mSize) index = mSize;
241 if (mSize >= mCapacity) return; // allocation failed
242
243 if (mOps) {
244 // Shift elements right, starting from the end
245 if (mSize > index) {
246 // Move-construct the last element into uninitialized space
247 mOps->move_construct(element_ptr(mSize), element_ptr(mSize - 1));
248 // Move-assign backwards for the rest
249 for (fl::size i = mSize - 1; i > index; --i) {
250 // Destroy dst, then move-construct from src
251 mOps->destroy(element_ptr(i));
252 mOps->move_construct(element_ptr(i), element_ptr(i - 1));
253 }
254 // Destroy the slot and copy-construct the new element
255 mOps->destroy(element_ptr(index));
256 }
257 mOps->copy_construct(element_ptr(index), element);
258 } else {
259 // Trivial: memmove right, then memcpy
260 if (mSize > index) {
261 trivial_move_left(element_ptr(index + 1), element_ptr(index),
262 mSize - index);
263 }
264 fl::memcpy(element_ptr(index), element, mElementSize);
265 }
266 ++mSize;
267}
const vector_element_ops * mOps
fl::size mElementSize
void ensure_capacity(fl::size n) FL_NOEXCEPT
Ensure capacity for at least n elements. Grows if needed.
void * element_ptr(fl::size index) FL_NOEXCEPT
Pointer to element at index (byte arithmetic).
void trivial_move_left(void *dst, const void *src, fl::size count) const FL_NOEXCEPT
void * memcpy(void *dest, const void *src, size_t n) FL_NOEXCEPT

References element_ptr(), ensure_capacity(), mCapacity, mElementSize, fl::memcpy(), mOps, mSize, and trivial_move_left().

Referenced by fl::vector< fl::i16 >::insert().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: