public member function
<unordered_map>
std::unordered_multimap::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_multimap container either the elements whose key is k or those in a range ([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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// unordered_multimap::erase
#include <iostream>
#include <unordered_map>
int main ()
{
std::unordered_multimap<std::string,std::string> myumm = {
{"strawberry","red"},
{"banana","yellow"},
{"orange","orange"},
{"lemon","yellow"},
{"apple","red"},
{"apple","green"},
{"pear","green"},
};
// erase examples:
myumm.erase ( myumm.begin() ); // erasing by iterator
myumm.erase ("apple"); // erasing by key (erases 2 elements)
myumm.erase ( myumm.find("orange"), myumm.end() ); // erasing by range
// show content:
for ( auto& x: myumm )
std::cout << x.first << ": " << x.second << std::endl;
return 0;
}
Possible output:
banana: yellow strawberry: red
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