std::unorde...ltiset::find(3)
๐ NAME ๐
std::unordered_multiset::find โ bestie, it's literally std::unordered_multiset::find, that's the whole name, no notes ๐
This one lives in the C++ Standard Libary manual, and the page itself is std::unorde...ltiset::find(3) (yes the title is truncated with dots, she's mysterious like that โจ).
โจ Synopsis โจ
okay so here's the whole menu, look at her go:
iterator find( const Key& key ); (1) (since C++11)
const_iterator find( const Key& key ) const; (2) (since C++11)
template< class K > (3) (since C++20)
iterator find( const K& x );
template< class K > (4) (since C++20)
const_iterator find( const K& x ) const;
(1),(2)โ these two look for an element whose key is equivalent tokey. โ ๏ธ And here's the tea: if the container has several elements with the key you asked for, any of them may be returned. Not the first, not the last, any. So don't get attached to a specific one, bestie ๐ญ(3),(4)โ these look for an element whose key compares equivalent to the valuex. But she's picky about showing up: this overload only participates in overload resolution ifHash::is_transparentandKeyEqual::is_transparentare both valid and each denotes a type. ๐ This assumes that suchHashis callable with bothKandKeytype, and that theKeyEqualis transparent โ and together? That's what lets you call this function without constructing an instance ofKey. No cap, that's the whole point, that's the vibe ๐ฆ
๐ Parameters ๐
keyโ the key value of the element you're searching for ๐xโ a value of any type that can be transparently compared with a key โจ
๐ธ Return value ๐ธ
An iterator to the element you requested, periodt. ๐
But if no such element is found? You get the past-the-end iterator (go peek at end(), she's right there) ๐ซถ
๐ฅ Complexity ๐ฅ
- Constant on average โญ
- Worst case linear in the size of the container ๐
๐ง Notes ๐ง
There's a feature-test macro for the heterogeneous girlies, and here's the whole row, not a single crumb left out:
- Feature-test macro:
__cpp_lib_generic_unordered_lookup - Value:
201811L - Std:
(C++20) - Feature: Heterogeneous comparison lookup in unordered associative containers; overloads
(3,4)๐
iykyk ๐
๐ Example ๐
// Run this code
#include <iostream>
#include <unordered_set>
int main()
{
// Simple comparison demo.
std::unordered_multiset<int> example = {1, 2, 3, 4};
if (auto search = example.find(2); search != example.end())
std::cout << "Found " << (*search) << '\n';
else
std::cout << "Not found\n";
}
๐ Output ๐
Found 2
she ate, honestly ๐
๐ See also ๐
countโ returns the number of elements matching a specific key (public member function) ๐งฎequal_rangeโ returns range of elements matching a specific key (public member function) ๐
okay that's the whole page, mwah ๐ โ sourced straight from http://cppreference.com, dated 2024.06.10, and it's the std::unorde...ltiset::find(3) page, go forth and find your elements bestie ๐ฆโจ๐
๐ฆ 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