std::unorde...ltimap::find(3)
π std::unordered_multimap::find π
okay so bestie, this whole page is for std::unorde...ltimap::find(3) from the C++ Standard Libary manual β yes, the header title is literally truncated like that, no cap. Weβre talking about std::unordered_multimap::find, and itβs here to help you find an element by key. periodt. β¨
πΈ NAME πΈ
std::unordered_multimap::find β thatβs the name, thatβs the whole assignment, and honestly? Iconic. π
β¨ Synopsis β¨
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;
So hereβs the overload tea, bestie:
(1),(2)β finds an element with key equivalent to key. If there are several elements with the requested key in the container, any of them may be returned. This is since C++11.(3),(4)β finds an element with key that compares equivalent to the value x. This overload participates in overload resolution only ifHash::is_transparentandKeyEqual::is_transparentare valid and each denotes a type. This assumes that suchHashis callable with bothKandKeytype, and that theKeyEqualis transparent, which, together, allows calling this function without constructing an instance ofKey. This is since C++20.
π 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 π¦
An iterator to the requested element. If no such element is found, past-the-end (see end()) iterator is returned. iykyk π
π Complexity π
Constant on average, worst case linear in the size of the container. Not me memorizing that for the vibe check π
π Notes π
Feature-test macro moment, bestie:
__cpp_lib_generic_unordered_lookupβ Value201811L, Std(C++20), Feature: βHeterogeneous comparison lookup in unordered associative containers; overloads (3,4)β.
π Example π
The example literally starts with // Run this code, so run it, bestie:
#include <iostream>
#include <unordered_map>
int main()
{
// Simple comparison demo.
std::unordered_multimap<int,char> example = {{1,'a'}, {2,'b'}};
if (auto search = example.find(2); search != example.end())
std::cout << "Found " << search->first << ' ' << search->second
<< '\n';
else
std::cout << "Not found\n";
}
Output:
Found 2 b
π See also π
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, bestie π«Ά source: http://cppreference.com; version/date: 2024.06.10; and the footer title is std::unorde...ltimap::find(3). Slay this lookup responsibly. πβ¨
π¦ 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