std::unorde...et::contains(3)
πΈ std::unordered_multiset::contains(3) πΈ
okay bestie, so this is a page from the C++ Standard Library manual β the whole vibe is std::unordered_multiset::contains, and the manual page itself is literally called std::unorde...et::contains(3) (yes the truncation is part of the aesthetic, don't come for her π
).
β¨ NAME β¨
std::unordered_multiset::contains β yeah. that's it. that's the name. it's giving "the function is the moment" π
π¦ Synopsis π¦
bool contains( const Key& key ) const; (1) (since C++20)
template< class K > (2) (since C++20)
bool contains( const K& x ) const;
so there's two flavors, both landing in C++20 era (iconic, we love a modern queen):
- Checks if there is an element with key equivalent to
keyin the container. simple. clean. slay. - Checks if there is an element with key that compares equivalent to the value
x.
and now the β¨fine printβ¨ for overload (2) β hear me out because this part actually matters:
This overload participates in overload resolution only if Hash::is_transparent and KeyEqual::is_transparent are valid and each denotes a type. This assumes that such Hash is callable with both K and Key type, and that the KeyEqual is transparent, which, together, allows calling this function without constructing an instance of Key.
translation: it's the "no extra object construction, we're efficient in this house" overload π«Ά iykyk.
π 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 the whole plot. binary. black and white. no in-between bestie π―
π₯ Complexity π₯
Constant on average, worst case linear in the size of the container. so like, usually she's fast, but worst case she's doing the whole walk-through. ngl keep that in mind π
π Example π
// Run this code
#include <iostream>
#include <unordered_set>
int main()
{
std::unordered_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? 2 ate, 5 did not. periodt πβ¨
π 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)
okay that's the whole page, no notes π§ and for the cute sign-off: this came from http://cppreference.com and the page is dated 2024.06.10 β the footer's out here repping std::unorde...et::contains(3) one more time for the girls ππ«Ά
π¦ 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