std::unordered_map::at(3)
π NAME π
This is the std::unordered_map::at(3) page from the C++ Standard Libary manual (yes, βLibaryβ is literally how itβs spelled up there, weβre not fixing the source π
).
std::unordered_map::at β std::unordered_map::at
β¨ Synopsis β¨
T& at( const Key& key ); (1) (since C++11)
const T& at( const Key& key ) const; (2) (since C++11)
template< class K > (3) (since C++26)
T& at( const K& x );
template< class K > (4) (since C++26)
const T& at( const K& x ) const;
Okay so bestie, this returns a reference to the mapped value of the element with the specified key. If no such element exists, an exception of type std::out_of_range is thrown. No silent vibes, it literally throws π
1,2) The key is equivalent to key.
3,4) The key compares equivalent to the value x. The reference to the mapped value is obtained as if by expression this->find(x)->second.
β οΈ The expression this->find(x) must be well-formed and have well-defined behavior, otherwise the behavior is undefined. That part is not a cute little detail, itβs the whole vibe check π«
These overloads participate 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. Thatβs the transparent-lookup slay π
πΈ Parameters πΈ
keyβ the key of the element to findxβ a value of any type that can be transparently compared with a key
π¦ Return value π¦
A reference to the mapped value of the requested element. Periodt.
π₯ Exceptions π₯
- 1,2)
std::out_of_rangeif the container does not have an element with the specifiedkey. - 3,4)
std::out_of_rangeif the container does not have the specified element, that is, iffind(x) == end()is true.
β Complexity β
Average case: constant, worst case: linear in size. So like, usually iconic, occasionally doing the most π
π§ Notes π§
Feature-test macro vibes:
- Feature-test macro:
__cpp_lib_associative_heterogeneous_insertion - Value:
202311L - Std: (C++26)
- Feature: Heterogeneous overloads for the remaining member functions in ordered and unordered associative containers. (3,4)
π Example π
This section is incomplete.
Reason: no example.
π See also π
operator[]β access or insert specified element (public member function)
π·οΈ Category π·οΈ
- Todo no example
Source/version + date sign-off: this page comes from http://cppreference.com, dated 2024.06.10, and itβs the std::unordered_map::at(3) page. πβ¨
π¦ 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