From fb403bc233b81a31cb6d84c6f41733c609371b97 Mon Sep 17 00:00:00 2001 From: Christian Mazakas Date: Tue, 18 Apr 2023 15:36:12 -0700 Subject: [PATCH] Add explicit allocator constructor --- include/boost/unordered/concurrent_flat_map.hpp | 5 +++++ test/cfoa/constructor_tests.cpp | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/boost/unordered/concurrent_flat_map.hpp b/include/boost/unordered/concurrent_flat_map.hpp index f87d3967..a7547b55 100644 --- a/include/boost/unordered/concurrent_flat_map.hpp +++ b/include/boost/unordered/concurrent_flat_map.hpp @@ -182,6 +182,11 @@ namespace boost { { } + explicit concurrent_flat_map(allocator_type a) + : table_(detail::foa::default_bucket_count, hasher(), key_equal(), a) + { + } + /// Capacity /// diff --git a/test/cfoa/constructor_tests.cpp b/test/cfoa/constructor_tests.cpp index 00d60072..e47cf1c1 100644 --- a/test/cfoa/constructor_tests.cpp +++ b/test/cfoa/constructor_tests.cpp @@ -312,7 +312,7 @@ namespace { map_type x(values.begin(), values.end(), 0, hasher(1), key_equal(2), allocator_type{}); - std::atomic_int num_transfers{0}; + std::atomic_uint num_transfers{0}; thread_runner( values, [&x, &reference_map, &num_transfers]( @@ -429,6 +429,21 @@ namespace { check_raii_counts(); } + UNORDERED_AUTO_TEST (explicit_allocator) { + raii::reset_counts(); + + { + allocator_type a; + map_type x(a); + + BOOST_TEST_EQ(x.size(), 0u); + BOOST_TEST_EQ(x.hash_function(), hasher()); + BOOST_TEST_EQ(x.key_eq(), key_equal()); + + BOOST_TEST(x.get_allocator() == a); + } + } + } // namespace // clang-format off