fork download
  1. #include <list>
  2. #include <iostream>
  3.  
  4. void removeElementsFromList(std::list<std::pair<void*, int>>& gatedClockNets, int maxFanout) {
  5. for (auto it = gatedClockNets.begin(); it != gatedClockNets.end(); ) {
  6. if (it->second >= maxFanout) {
  7. // Remove the element and advance the iterator
  8. it = gatedClockNets.erase(it);
  9. } else {
  10. // Increment the iterator
  11. ++it;
  12. }
  13. }
  14. }
  15.  
  16. int main() {
  17. // Example list of pairs
  18. std::list<std::pair<void*, int>> gatedClockNets = {
  19. {nullptr, 3}, {nullptr, 5}, {nullptr, 2}, {nullptr, 7}
  20. };
  21.  
  22. int maxFanout = 7;
  23.  
  24. std::cout << "Before removal:" << std::endl;
  25. for (const auto& pair : gatedClockNets) {
  26. std::cout << "Fanout: " << pair.second << std::endl;
  27. }
  28.  
  29. removeElementsFromList(gatedClockNets, maxFanout);
  30.  
  31. std::cout << "After removal:" << std::endl;
  32. for (const auto& pair : gatedClockNets) {
  33. std::cout << "Fanout: " << pair.second << std::endl;
  34. }
  35.  
  36. return 0;
  37. }
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
Before removal:
Fanout: 3
Fanout: 5
Fanout: 2
Fanout: 7
After removal:
Fanout: 3
Fanout: 5
Fanout: 2