FastLED 3.10.8
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 249 of file basic_vector.cpp.hpp.

249 {
250 if (index > mSize) index = mSize;
252 if (mSize >= mCapacity) return; // allocation failed
253
254 if (mOps) {
255 // Shift elements right, starting from the end
256 if (mSize > index) {
257 // Move-construct the last element into uninitialized space
258 mOps->move_construct(element_ptr(mSize), element_ptr(mSize - 1));
259 // Move-assign backwards for the rest
260 for (fl::size i = mSize - 1; i > index; --i) {
261 // Destroy dst, then move-construct from src
262 mOps->destroy_n(element_ptr(i), 1);
263 mOps->move_construct(element_ptr(i), element_ptr(i - 1));
264 }
265 // Destroy the slot and copy-construct the new element
266 mOps->destroy_n(element_ptr(index), 1);
267 }
268 mOps->copy_construct(element_ptr(index), element);
269 } else {
270 // Trivial: memmove right, then memcpy
271 if (mSize > index) {
272 trivial_move_left(element_ptr(index + 1), element_ptr(index),
273 mSize - index);
274 }
275 fl::memcpy(element_ptr(index), element, mElementSize);
276 }
277 ++mSize;
278}
const vector_element_ops * mOps
void ensure_capacity(fl::size n) FL_NO_EXCEPT
Ensure capacity for at least n elements. Grows if needed.
void * element_ptr(fl::size index) FL_NO_EXCEPT
Pointer to element at index (byte arithmetic).
fl::size mElementSize
void trivial_move_left(void *dst, const void *src, fl::size count) const FL_NO_EXCEPT
FASTLED_FORCE_INLINE void * memcpy(void *dest, const void *src, size_t n) FL_NO_EXCEPT
Definition cstring.h:136

References element_ptr(), ensure_capacity(), fl::FL_NO_EXCEPT, 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: