#include <list>
#include <iostream>

void removeElementsFromList(std::list<std::pair<void*, int>>& gatedClockNets, int maxFanout) {
    for (auto it = gatedClockNets.begin(); it != gatedClockNets.end(); ) {
        if (it->second >= maxFanout) {
            // Remove the element and advance the iterator
            it = gatedClockNets.erase(it);
        } else {
            // Increment the iterator
            ++it;
        }
    }
}

int main() {
    // Example list of pairs
    std::list<std::pair<void*, int>> gatedClockNets = {
        {nullptr, 3}, {nullptr, 5}, {nullptr, 2}, {nullptr, 7}
    };

    int maxFanout = 7;

    std::cout << "Before removal:" << std::endl;
    for (const auto& pair : gatedClockNets) {
        std::cout << "Fanout: " << pair.second << std::endl;
    }

    removeElementsFromList(gatedClockNets, maxFanout);

    std::cout << "After removal:" << std::endl;
    for (const auto& pair : gatedClockNets) {
        std::cout << "Fanout: " << pair.second << std::endl;
    }

    return 0;
}