Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Defect Report] unordered_map needs an at() member function

40 views
Skip to first unread message

Joe Gottman

unread,
Nov 15, 2007, 9:31:28 AM11/15/07
to

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.

Proposed Resolution:

Add the following functions to the definition of unordered_map under
"lookup" (23.4.1):

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


Add the following definitions to 23.4.1.2:

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.

Joe Gottman

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std...@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]

0 new messages