MCPcopy Create free account
hub / github.com/FastLED/FastLED / test_erase_while_iterating

Function test_erase_while_iterating

tests/misc/containers.cpp:911–942  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

909// Erase while iterating for sequential containers (Pattern 1)
910template<template<typename> class ContainerTemplate>
911void test_erase_while_iterating() {
912 using Container = ContainerTemplate<int>;
913 Container c;
914 // Insert multiple elements
915 for (int i = 1; i <= 5; ++i) {
916 c.push_back(i);
917 }
918
919 FL_CHECK(c.size() == 5);
920
921 // Erase every other element while iterating
922 int erased_count = 0;
923 for (auto it = c.begin(); it != c.end(); ) {
924 if (*it % 2 == 0) {
925 it = c.erase(it); // erase returns next iterator
926 erased_count++;
927 } else {
928 ++it;
929 }
930 }
931
932 FL_CHECK(erased_count == 2); // Elements 2 and 4 were erased
933 FL_CHECK(c.size() == 3); // Elements 1, 3, 5 remain
934
935 // Verify remaining elements
936 int count = 0;
937 for (auto it = c.begin(); it != c.end(); ++it) {
938 count++;
939 FL_CHECK(*it % 2 == 1); // All remaining should be odd
940 }
941 FL_CHECK(count == 3);
942}
943
944// Erase while iterating for map containers (Pattern 2)
945template<typename Map>

Callers

nothing calls this directly

Calls 5

push_backMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected