From b964fa777cde8ffd736a41a0b03bf10a4ad61e8b Mon Sep 17 00:00:00 2001 From: Christian Mazakas Date: Fri, 7 Oct 2022 08:41:30 -0700 Subject: [PATCH] Add at_tests --- .../boost/unordered/unordered_flat_map.hpp | 22 +++++++++++++++++++ test/Jamfile.v2 | 1 + test/unordered/at_tests.cpp | 10 +++++++++ 3 files changed, 33 insertions(+) diff --git a/include/boost/unordered/unordered_flat_map.hpp b/include/boost/unordered/unordered_flat_map.hpp index 64175639..de48a22d 100644 --- a/include/boost/unordered/unordered_flat_map.hpp +++ b/include/boost/unordered/unordered_flat_map.hpp @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -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; diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 5e3b82ed..332b3a21 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -111,3 +111,4 @@ build_foa insert_hint_tests ; build_foa emplace_tests ; build_foa erase_tests ; build_foa find_tests ; +build_foa at_tests ; diff --git a/test/unordered/at_tests.cpp b/test/unordered/at_tests.cpp index 25b0951a..921bb8ee 100644 --- a/test/unordered/at_tests.cpp +++ b/test/unordered/at_tests.cpp @@ -5,7 +5,12 @@ // clang-format off #include "../helpers/prefix.hpp" +#ifdef BOOST_UNORDERED_FOA_TESTS +#include +#include +#else #include +#endif #include "../helpers/postfix.hpp" // clang-format on @@ -17,8 +22,13 @@ namespace at_tests { UNORDERED_AUTO_TEST (at_tests) { BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Create Map" << std::endl; +#ifdef BOOST_UNORDERED_FOA_TESTS + boost::unordered_flat_map x; + boost::unordered_flat_map const& x_const(x); +#else boost::unordered_map x; boost::unordered_map const& x_const(x); +#endif BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Check empty container" << std::endl;