Title
unordered_map needs an at() member function
Status
cd1
Section
[unord.map.elem]
Submitter
Joe Gottman

Created on 2007-11-15.00:00:00 last changed 164 months ago

Messages

Date: 2010-10-21.18:28:33

[ Bellevue: Editorial note: the "(unique)" differs from map. ]

Date: 2010-10-21.18:28:33

Proposed resolution:

Add the following functions to the definition of unordered_map under "lookup" ([unord.map]):

mapped_type& at(const key_type& k);
const mapped_type &at(const key_type &k) const;

Add the following definitions to [unord.map.elem]:

mapped_type& at(const key_type& k);
const mapped_type &at(const key_type &k) const;

Returns: A reference to x.second, where x is the (unique) element whose key is equivalent to k.

Throws: An exception object of type out_of_range if no such element is present.

Date: 2007-11-15.00:00:00

The new member function at() was recently added to std::map(). It acts like operator[](), except it throws an exception when the input key is not found. It is useful when the map is const, the value_type of the key doesn't have a default constructor, it is an error if the key is not found, or the user wants to avoid accidentally adding an element to the map. For exactly these same reasons, at() would be equally useful in std::unordered_map.

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg3685
2010-10-21 18:28:33adminsetmessages: + msg3684
2007-11-15 00:00:00admincreate