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

Function test_map_erase_while_iterating

tests/misc/containers.cpp:946–980  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

944// Erase while iterating for map containers (Pattern 2)
945template<typename Map>
946void test_map_erase_while_iterating() {
947 Map m;
948 // Insert multiple elements
949 for (int i = 1; i <= 5; ++i) {
950 m.insert(fl::make_pair(i, i * 10));
951 }
952
953 FL_CHECK(m.size() == 5);
954
955 // Erase every other element while iterating
956 int erased_count = 0;
957 for (auto it = m.begin(); it != m.end(); ) {
958 if (it->first % 2 == 0) {
959 it = m.erase(it); // erase returns next iterator
960 erased_count++;
961 } else {
962 ++it;
963 }
964 }
965
966 FL_CHECK(erased_count == 2); // Keys 2 and 4 were erased
967 FL_CHECK(m.size() == 3); // Keys 1, 3, 5 remain
968
969 // Verify remaining elements
970 FL_CHECK(m.count(1) > 0);
971 FL_CHECK(m.count(3) > 0);
972 FL_CHECK(m.count(5) > 0);
973 FL_CHECK(m.count(2) == 0);
974 FL_CHECK(m.count(4) == 0);
975
976 // Verify values
977 auto it = m.find(1);
978 FL_CHECK(it != m.end());
979 FL_CHECK(it->second == 10);
980}
981
982// ============================================================================
983// PATTERN 3: CONTAINER FACTORY (Complex Initialization)

Callers

nothing calls this directly

Calls 8

make_pairFunction · 0.85
insertMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
eraseMethod · 0.45
countMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected