(C++17) | ||||
Sequence | ||||
(C++11) | ||||
(C++26) | ||||
(C++26) | ||||
(C++11) | ||||
Associative | ||||
Unordered associative | ||||
(C++11) | ||||
(C++11) | ||||
(C++11) | ||||
(C++11) | ||||
Adaptors | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
Views | ||||
(C++20) | ||||
(C++23) | ||||
Tables | ||||
Iterator invalidation | ||||
Member function table | ||||
Non-member function table |
std::unordered_set
Member types | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Member functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Non-member functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Deduction guides(C++17) |
bool contains(const Key& key)const; | (1) | (since C++20) (constexpr since C++26) |
template<class K> bool contains(const K& x)const; | (2) | (since C++20) (constexpr since C++26) |
Hash
andKeyEqual
are bothtransparent. This assumes that suchHash
is callable with bothK
andKey
type, and that theKeyEqual
is transparent, which, together, allows calling this function without constructing an instance ofKey
.Contents |
key | - | key value of the element to search for |
x | - | a value of any type that can be transparently compared with a key |
true if there is such an element, otherwisefalse.
Constant on average, worst case linear in the size of the container.
#include <iostream>#include <unordered_set> int main(){std::unordered_set<int> example{1,2,3,4}; for(int x:{2,5})if(example.contains(x))std::cout<< x<<": Found\n";elsestd::cout<< x<<": Not found\n";}
Output:
2: Found5: Not found
finds element with specific key (public member function)[edit] | |
returns the number of elements matching specific key (public member function)[edit] | |
returns range of elements matching a specific key (public member function)[edit] |