std::unordered_map::at(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸŽ€ 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 find
  • x β€” 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_range if the container does not have an element with the specified key.
  • 3,4) std::out_of_range if the container does not have the specified element, that is, if find(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