mirror of
https://github.com/boostorg/unordered.git
synced 2025-11-13 05:49:54 +01:00
Add at_tests
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
|
||||
#include <initializer_list>
|
||||
#include <iterator>
|
||||
#include <stdexcept>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
@@ -287,6 +288,27 @@ namespace boost {
|
||||
/// Lookup
|
||||
///
|
||||
|
||||
mapped_type& at(key_type const& key)
|
||||
{
|
||||
auto pos = table_.find(key);
|
||||
if (pos != table_.end()) {
|
||||
return pos->second;
|
||||
}
|
||||
// TODO: someday refactor this to conditionally serialize the key and
|
||||
// include it in the error message
|
||||
//
|
||||
throw std::out_of_range("key was not found in unordered_flat_map");
|
||||
}
|
||||
|
||||
mapped_type const& at(key_type const& key) const
|
||||
{
|
||||
auto pos = table_.find(key);
|
||||
if (pos != table_.end()) {
|
||||
return pos->second;
|
||||
}
|
||||
throw std::out_of_range("key was not found in unordered_flat_map");
|
||||
}
|
||||
|
||||
mapped_type& operator[](key_type const& key)
|
||||
{
|
||||
return table_.try_emplace(key).first->second;
|
||||
|
||||
Reference in New Issue
Block a user