public member function
<unordered_set>
std::unordered_multiset::erase by position (1)iterator erase ( const_iterator position );by key (2)
size_type erase ( const key_type& k );range (3)
iterator erase ( const_iterator first, const_iterator last );
Erase elements
Removes from the unordered_multiset container either the elements whose value is k or a range of elements ([first,last)).This effectively reduces the container size by the number of elements removed, calling each element's destructor.
Member type iterator is a forward iterator type.
All iterators in an unordered_multiset have const access to the elements: Elements can be inserted or removed, but not modified while in the container.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// unordered_multiset::erase
#include <iostream>
#include <string>
#include <unordered_set>
int main ()
{
std::unordered_multiset<std::string> myums =
{"fish","duck","cow","cow","pig","hen","sheep"};
myums.erase ( myums.begin() ); // erasing by iterator
myums.erase ( "sheep" ); // erasing by key
myums.erase ( myums.find("fish"), myums.end() ); // erasing by range
std::cout << "myums contains:";
for ( const std::string& x: myums ) std::cout << " " << x;
std::cout << std::endl;
return 0;
}
Possible output:
myums contains: pig cow cow
The relative order of iteration of equivalent elements not removed by the operation is preserved.
The relative order of iteration of the elements not removed by the operation is preserved.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4