Przejdź do głównej zawartości

std::unordered_map at() method

// (1) Non const version
T& at( const Key& key );

// (2) Const version
const T& at( const Key& key ) const;

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

Parameters

  • key - the key of the element to find

Return value

Reference to the mapped value of the requested element.

Complexity

Average case, constant - O(1).
Worst case, linear in size of the containter - O(log size()).

Exceptions

std::out_of_range if the container does not have an element with the specified key.

Examples

important

This section requires improvement. You can help by editing this doc page.

This article originates from this CppReference page. It was likely altered for improvements or editors' preference. Click "Edit this page" to see all changes made to this document.
Hover to see the original license.

std::unordered_map at() method

// (1) Non const version
T& at( const Key& key );

// (2) Const version
const T& at( const Key& key ) const;

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

Parameters

  • key - the key of the element to find

Return value

Reference to the mapped value of the requested element.

Complexity

Average case, constant - O(1).
Worst case, linear in size of the containter - O(log size()).

Exceptions

std::out_of_range if the container does not have an element with the specified key.

Examples

important

This section requires improvement. You can help by editing this doc page.

This article originates from this CppReference page. It was likely altered for improvements or editors' preference. Click "Edit this page" to see all changes made to this document.
Hover to see the original license.