Using erase_If with Set in C++ STL
The erase_if function in C++20 is used to erase all the elements in the set satisfying the required condition. This condition is referred to as the predicate.
The syntax for the erase_if function is
The first argument of erase function is the set in which elements need to be erased. The second argument is the predicate which is the condition to be satisfied.
In this example, we are considering a set of the first 10 natural numbers and using the erase_if function to erase all odd elements from the set.
Original set: 1 2 3 4 5 6 7 8 9 10 After removing odd elements from the set using erase_if 1 3 5 7 9
Note: erase_if function is available in C++20 and GeeksForGeeks Compiler supports only till C++14 thus you will get an error if you will try running code here.