(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 |
bool contains(const Key& key)const; | (1) | (since C++23) (constexpr since C++26) |
template<class K> bool contains(const K& x)const; | (2) | (since C++23) (constexpr since C++26) |
Compare
istransparent. It 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.
Logarithmic in the size of the container.
#include <iostream>#include <flat_map> int main(){std::flat_map<int,char> example{{1,'a'},{2,'b'}}; 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] |