std::multiset::contains(3)
๐ std::multiset::contains โ C++ Standard Libary manual ๐
(section 3, bestie)
Okay so you opened the std::multiset::contains(3) page and yes, you're in the C++ Standard Libary manual โ iconic, we love a standard-library moment. โจ
๐ธ NAME ๐ธ
It's literally std::multiset::contains โ that's the function name AND the page name. No plot twist, just main character energy. ๐
๐ฆ Synopsis ๐ฆ
Here's the whole signature situation, copied exactly so nobody comes for me:
bool contains( const Key& key ) const; (1) (since C++20)
template< class K > (2) (since C++20)
bool contains( const K& x ) const;
- Checks if there's an element with key equivalent to
keyin the container. ๐ - Checks if there's an element with key that compares equivalent to the value
x.
This overload only participates in overload resolution if the qualified-id Compare::is_transparent is valid and denotes a type. It lets you call this function without constructing an instance of Key. Slay, transparent comparison, slay. ๐
๐ง Parameters ๐ง
keyโ key value of the element to search for ๐xโ a value of any type that can be transparently compared with a key ๐
โญ Return value โญ
true if there is such an element, otherwise false. That's it. Simple. Clean. Periodt. ๐
๐ฅ Complexity ๐ฅ
Logarithmic in the size of the container. So it's giving efficient, not chaotic. ๐ธ
๐ Example ๐
// Run this code
#include <iostream>
#include <set>
int main()
{
std::multiset<int> example{1, 2, 3, 4};
for (int x : {2, 5})
if (example.contains(x))
std::cout << x << ": Found\n";
else
std::cout << x << ": Not found\n";
}
๐ Output ๐
2: Found
5: Not found
๐ See also ๐
findโ finds element with specific key (public member function) ๐countโ returns the number of elements matching specific key (public member function) ๐งฎequal_rangeโ returns range of elements matching a specific key (public member function) ๐ซถ
mwah ๐ this little gem lives at http://cppreference.com, dated 2024.06.10, and it is officially the std::multiset::contains(3) page โ bye bestie, go check those keys! ๐ฆ๐
๐ฆ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 ยท MIT
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms