Add at_tests

This commit is contained in:
Christian Mazakas
2022-10-07 08:41:30 -07:00
parent cde017f791
commit b964fa777c
3 changed files with 33 additions and 0 deletions

View File

@@ -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;