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

◆ insert()

template<typename T, size_t N>
bool fl::FixedVector< T, N >::insert ( iterator pos,
const T & value )
inline

Definition at line 227 of file vector.h.

227 {
228 if (current_size < N) {
229 // shift all elements to the right
230 // for (iterator p = end(); p != pos; --p) {
231 // new (p) T(*(p - 1)); // Use copy constructor instead of
232 // std::move (p - 1)->~T();
233 // }
234 // new (pos) T(value);
235 // shift all element from pos to end to the right
236 for (iterator p = end(); p != pos; --p) {
237 // LOOKS LIKE THERE ARE BUGS AROUND THIS INSERT FUNCTION.
238 // I'VE TRIED TO UPGRADE THE CODE TO USE TEMPORARIES BUT
239 // IT SEEMS TO NOT WORK. IT COULD POSSIBLY DO WITH ALIGNMENT
240 // OF THE DATA. THIS IMPL HAS ISSUES WITH THE NEW PLACE
241 // OPERATION.
242 T temp = *(p - 1);
243 (p)->~T(); // Destroy the current element
244 // Clear the memory
245 void *vp = static_cast<void *>(p);
246 memset(vp, 0, sizeof(T));
247 new (p) T(temp); // Use copy constructor instead of std::move
248 //(p - 1)->~T();
249 }
250 ++current_size;
251 // now insert the new value
252 new (pos) T(value);
253 return true;
254 }
255 return false;
256 }
size_t current_size
Definition vector.h:302
iterator end()
Definition vector.h:285