public member function
<unordered_set>
std::unordered_set::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_set container either a single element 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_set 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_set::erase
#include <iostream>
#include <string>
#include <unordered_set>
int main ()
{
std::unordered_set<std::string> myset =
{"USA","Canada","France","UK","Japan","Germany","Italy"};
myset.erase ( myset.begin() ); // erasing by iterator
myset.erase ( "France" ); // erasing by key
myset.erase ( myset.find("Japan"), myset.end() ); // erasing by range
std::cout << "myset contains:";
for ( const std::string& x: myset ) std::cout << " " << x;
std::cout << std::endl;
return 0;
}
Possible output:
myset contains: Canada USA Italy
Only the iterators and references to the elements removed are invalidated.
The rest are unaffected.
Only the iterators and references to the elements removed are invalidated.
The rest are unaffected.
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