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;

View File

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

View File

@ -5,7 +5,12 @@
// clang-format off
#include "../helpers/prefix.hpp"
#ifdef BOOST_UNORDERED_FOA_TESTS
#include <boost/unordered/unordered_flat_map.hpp>
#include <boost/unordered/detail/implementation.hpp>
#else
#include <boost/unordered_map.hpp>
#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<std::string, int> x;
boost::unordered_flat_map<std::string, int> const& x_const(x);
#else
boost::unordered_map<std::string, int> x;
boost::unordered_map<std::string, int> const& x_const(x);
#endif
BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Check empty container" << std::endl;