unordered_set();
| template< class Key, class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class Allocator = std::allocator<Key>
| > class unordered_set; | (1) | (since C++11) |
|---|---|---|
| namespace pmr { | ||
| template< | ||
| class Key, | ||
| class Hash = std::hash<Key>, | ||
| class Pred = std::equal_to<Key> | ||
| > using unordered_set = std::unordered_set<Key, Hash, Pred, | ||
| std::pmr::polymorphic_allocator<Key>>; | ||
| } |
#include <iostream>
#include <unordered_set>
void print(const auto& set)
{
for (const auto& elem : set)
std::cout << elem << ' ';
std::cout << '\\n';
}
int main()
{
std::unordered_set<int> mySet{2, 7, 1, 8, 2, 8}; // creates a set of ints
print(mySet);
mySet.insert(5); // puts an element 5 in the set
print(mySet);
if (auto iter = mySet.find(5); iter != mySet.end())
mySet.erase(iter); // removes an element pointed to by iter
print(mySet);
mySet.erase(7); // removes an element 7
print(mySet);
}
result
8 1 7 2
5 8 1 7 2
8 1 7 2
8 1 2