std::map::at(3)

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

🌸 NAME 🌸

std::map::at β€” std::map::at (yes bestie, the name is literally the name πŸ’…). This is the manual page for std::map::at(3), from the C++ Standard Libary, and we are about to make it make sense 🫢


✨ Synopsis ✨

T& at( const Key& key );             (1)
const T& at( const Key& key ) const; (2)
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;

Returns a reference to the mapped value of the element with specified key. If no such element exists, an exception of type std::out_of_range is thrown.

  1. 1,2) The key is equivalent to key.
  2. 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. These overloads participate in overload resolution only if the qualified-id Compare::is_transparent is valid and denotes a type. It allows calling this function without constructing an instance of Key.

πŸŽ€ 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. That's the whole vibe ✨


😭 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 πŸ”₯

Logarithmic in the size of the container. So like, it scales, but not in a scary way πŸ‘‘


πŸ§ͺ Notes πŸ§ͺ

  • 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

No cap, there is literally no example here yet 😭


πŸ“‹ Defect reports πŸ“‹

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

  • DR LWG 464 β€” applied to C++98 β€” behavior as published: map did not have this member function β€” correct behavior: added
  • DR LWG 703 β€” applied to C++98 β€” behavior as published: the complexity requirement was missing β€” correct behavior: added
  • DR LWG 2007 β€” applied to C++98 β€” behavior as published: the return value referred to the requested element β€” correct behavior: refers to its mapped value

🌈 See also 🌈

  • operator[] β€” access or insert specified element (public member function)

🏷️ Category 🏷️

* Todo no example


With love and logarithmic vibes πŸ’– β€” this page came from cppreference.com, version/date 2024.06.10, manual std::map::at(3) 🫢✨

πŸ“¦ where this page comes from