The unordered_multiset::erase() function is a built-in function in C++ STL which is used to remove either a single element or, all elements with a definite value or, a range of elements ranging from start(inclusive) to end(exclusive). This decreases the size of the container by the number of elements removed.
- unordered_multiset_name.erase(iterator position)
- unordered_multiset_name.erase(iterator start, iterator end)
Parameters: This function has three versions.
- The first one takes an iterator as an argument, erases the element present at that position.
- The second version takes two iterator(say start and end) takes 2 iterators as argument and erases all elements in the range [start, end).
- The third version takes a key value as argument and erases all elements of that value in the multiset.
Return Value: The 1st and 2nd version of the function as shown in the above syntax returns an iterator immediately following the last element erased. The 3rd version returns the number of element erased.
Below programs illustrate the unordered_multiset::erase() function:
10 10 15 15 20 20 25 MultiSet size: 0
5 15 15 20 20 25
- map erase() function in C++ STL
- unordered_set erase() function in C++ STL
- list erase() function in C++ STL
- set::erase in C++ STL
- unordered_multimap erase in C++ STL
- multimap::erase() in C++ STL
- std::string::erase in C++
- multiset erase() in C++ STL
- unordered_map erase in C++ STL
- vector erase() and clear() in C++
- Different ways to delete elements in std::map (erase() and clear())
- Difference between std::remove and vector::erase for vectors
- deque::clear() and deque::erase() in C++ STL
- Function Overloading vs Function Overriding in C++
- What happens when a virtual function is called inside a non-virtual function in C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.