Loop on newly added elements of std::unorderd_map

63 Views Asked by At

During a loop on an std::unordered_map I need in some cases to add a new element to the map:

for (auto &element : map) {
  if (condition) {
    map.insert(newElement);
  }
  // Do something with element
}

It happens that newElement might be inserted before element, so that it is not processed by the loop. How can I modify the code so that all of the eventually added elements are processed by the loop?

0

There are 0 best solutions below