Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::unordered_map<Key,T,Hash,KeyEqual,Allocator>::at

      From cppreference.com
      <cpp‎ |container‎ |unordered map

      [edit template]
       
       
       
      std::unordered_map
      Member types
      Member functions
      Non-member functions
      Deduction guides(C++17)
       
      T& at(const Key& key);
      (1)(since C++11)
      const T& at(const Key& key)const;
      (2)(since C++11)
      template<class K>
      T& at(const K& x);
      (3)(since C++26)
      template<class K>
      const T& at(const K& x)const;
      (4)(since C++26)

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

      1,2) The key is equivalent tokey.
      3,4) The key comparesequivalent to the valuex. The reference to the mapped value is obtained as if by expressionthis->find(x)->second.
      The expressionthis->find(x) must be well-formed and have well-defined behavior, otherwise the behavior is undefined.
      These overloads participate in overload resolution only ifHash andKeyEqual are bothtransparent. This assumes that suchHash is callable with bothK andKey type, and that theKeyEqual is transparent, which, together, allows calling this function without constructing an instance ofKey.

      Contents

      [edit]Parameters

      key - the key of the element to find
      x - a value of any type that can be transparently compared with a key

      [edit]Return value

      A reference to the mapped value of the requested element.

      [edit]Exceptions

      1,2)std::out_of_range if the container does not have an element with the specifiedkey.
      3,4)std::out_of_range if the container does not have the specified element, that is, iffind(x)== end() istrue.

      [edit]Complexity

      Average case: constant, worst case: linear in size.

      Notes

      Feature-test macroValueStdFeature
      __cpp_lib_associative_heterogeneous_insertion202311L(C++26)Heterogeneous overloads for the remaining member functions inordered andunordered associativecontainers.(3,4)

      [edit]Example

      This section is incomplete
      Reason: no example

      [edit]See also

      access or insert specified element
      (public member function)[edit]
      finds element with specific key
      (public member function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/container/unordered_map/at&oldid=131156"

      [8]ページ先頭

      ©2009-2025 Movatter.jp