diff --git a/include/boost/unordered/unordered_flat_map.hpp b/include/boost/unordered/unordered_flat_map.hpp index 9f077d7a..3bb3122b 100644 --- a/include/boost/unordered/unordered_flat_map.hpp +++ b/include/boost/unordered/unordered_flat_map.hpp @@ -51,14 +51,6 @@ namespace boost { using iterator = typename table_type::iterator; using const_iterator = typename table_type::const_iterator; - iterator begin() noexcept { return table_.begin(); } - const_iterator begin() const noexcept { return table_.begin(); } - const_iterator cbegin() const noexcept { return table_.cbegin(); } - - iterator end() noexcept { return table_.end(); } - const_iterator end() const noexcept { return table_.end(); } - const_iterator cend() const noexcept { return table_.cend(); } - unordered_flat_map() : unordered_flat_map(0) {} explicit unordered_flat_map(size_type n, hasher const& h = hasher(), @@ -68,6 +60,16 @@ namespace boost { { } + unordered_flat_map(size_type n, allocator_type const& a) + : unordered_flat_map(n, hasher(), key_equal(), a) + { + } + + explicit unordered_flat_map(allocator_type const& a) + : unordered_flat_map(0, a) + { + } + template unordered_flat_map(Iterator first, Iterator last, size_type n = 0, hasher const& h = hasher(), key_equal const& pred = key_equal(), @@ -77,6 +79,30 @@ namespace boost { this->insert(first, last); } + unordered_flat_map(std::initializer_list ilist, + size_type n = 0, hasher const& h = hasher(), + key_equal const& pred = key_equal(), + allocator_type const& a = allocator_type()) + : unordered_flat_map(ilist.begin(), ilist.end(), n, h, pred, a) + { + } + + allocator_type get_allocator() const noexcept + { + return table_.get_allocator(); + } + + /// Iterators + /// + + iterator begin() noexcept { return table_.begin(); } + const_iterator begin() const noexcept { return table_.begin(); } + const_iterator cbegin() const noexcept { return table_.cbegin(); } + + iterator end() noexcept { return table_.end(); } + const_iterator end() const noexcept { return table_.end(); } + const_iterator cend() const noexcept { return table_.cend(); } + /// Capacity /// @@ -246,6 +272,9 @@ namespace boost { return {pos, next}; } + /// Hash Policy + /// + size_type bucket_count() const noexcept { return table_.capacity(); } float load_factor() const noexcept { return table_.load_factor(); } @@ -255,6 +284,13 @@ namespace boost { return table_.max_load_factor(); } + void max_load_factor(float) {} + + /// Observers + /// + + hasher hash_function() const { return table_.hash_function(); } + key_equal key_eq() const { return table_.key_eq(); } }; } // namespace unordered diff --git a/include/boost/unordered/unordered_flat_set.hpp b/include/boost/unordered/unordered_flat_set.hpp index cec24f18..c7bed6fc 100644 --- a/include/boost/unordered/unordered_flat_set.hpp +++ b/include/boost/unordered/unordered_flat_set.hpp @@ -59,6 +59,16 @@ namespace boost { { } + unordered_flat_set(size_type n, allocator_type const& a) + : unordered_flat_set(n, hasher(), key_equal(), a) + { + } + + explicit unordered_flat_set(allocator_type const& a) + : unordered_flat_set(0, a) + { + } + template unordered_flat_set(Iterator first, Iterator last, size_type n = 0, hasher const& h = hasher(), key_equal const& pred = key_equal(), @@ -68,6 +78,22 @@ namespace boost { this->insert(first, last); } + unordered_flat_set(std::initializer_list ilist, + size_type n = 0, hasher const& h = hasher(), + key_equal const& pred = key_equal(), + allocator_type const& a = allocator_type()) + : unordered_flat_set(ilist.begin(), ilist.end(), n, h, pred, a) + { + } + + allocator_type get_allocator() const noexcept + { + return table_.get_allocator(); + } + + /// Iterators + /// + iterator begin() noexcept { return table_.begin(); } const_iterator begin() const noexcept { return table_.begin(); } const_iterator cbegin() const noexcept { return table_.cbegin(); } @@ -173,6 +199,9 @@ namespace boost { return {pos, next}; } + /// Hash Policy + /// + size_type bucket_count() const noexcept { return table_.capacity(); } float load_factor() const noexcept { return table_.load_factor(); } @@ -182,6 +211,13 @@ namespace boost { return table_.max_load_factor(); } + void max_load_factor(float) {} + + /// Observers + /// + + hasher hash_function() const { return table_.hash_function(); } + key_equal key_eq() const { return table_.key_eq(); } }; } // namespace unordered diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index bee68b6c..b07b2313 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -48,6 +48,7 @@ run unordered/incomplete_test.cpp ; run unordered/simple_tests.cpp ; run unordered/equivalent_keys_tests.cpp ; run unordered/constructor_tests.cpp ; +run unordered/constructor_tests.cpp : : : $(CPP14) BOOST_UNORDERED_FOA_TESTS : foa_constructor_tests ; run unordered/copy_tests.cpp ; run unordered/move_tests.cpp ; run unordered/assign_tests.cpp ; diff --git a/test/unordered/constructor_tests.cpp b/test/unordered/constructor_tests.cpp index c2a43283..2b9d3d17 100644 --- a/test/unordered/constructor_tests.cpp +++ b/test/unordered/constructor_tests.cpp @@ -1,14 +1,20 @@ // Copyright 2006-2010 Daniel James. +// Copyright (C) 2022 Christian Mazakas // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +#ifdef BOOST_UNORDERED_FOA_TESTS +#include +#include +#else // clang-format off #include "../helpers/prefix.hpp" #include #include #include "../helpers/postfix.hpp" // clang-format on +#endif #include "../helpers/test.hpp" #include "../objects/test.hpp" @@ -497,6 +503,35 @@ namespace constructor_tests { test::check_equivalent_keys(x); } + using test::default_generator; + using test::generate_collisions; + using test::limited_range; + +#ifdef BOOST_UNORDERED_FOA_TESTS + boost::unordered_flat_map >* test_map_std_alloc; + + boost::unordered_flat_set >* test_set; + boost::unordered_flat_map >* test_map; + + UNORDERED_TEST(constructor_tests1, + ((test_map_std_alloc)(test_set)(test_map))( + (default_generator)(generate_collisions)(limited_range))) + + UNORDERED_TEST(constructor_tests2, + ((test_set)(test_map))( + (default_generator)(generate_collisions)(limited_range))) + + UNORDERED_TEST(map_constructor_test, + ((test_map_std_alloc)(test_map))( + (default_generator)(generate_collisions)(limited_range))) + + UNORDERED_TEST(no_alloc_default_construct_test, + ((test_set)(test_map))( + (default_generator)(generate_collisions)(limited_range))) +#else boost::unordered_map >* test_map_std_alloc; @@ -509,10 +544,6 @@ namespace constructor_tests { boost::unordered_multimap >* test_multimap; - using test::default_generator; - using test::generate_collisions; - using test::limited_range; - UNORDERED_TEST(constructor_tests1, ((test_map_std_alloc)(test_set)(test_multiset)(test_map)(test_multimap))( (default_generator)(generate_collisions)(limited_range))) @@ -528,12 +559,17 @@ namespace constructor_tests { UNORDERED_TEST(no_alloc_default_construct_test, ((test_set)(test_multiset)(test_map)(test_multimap))( (default_generator)(generate_collisions)(limited_range))) +#endif #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) UNORDERED_AUTO_TEST (test_default_initializer_list) { std::initializer_list init; +#ifdef BOOST_UNORDERED_FOA_TESTS + boost::unordered_flat_set x1 = init; +#else boost::unordered_set x1 = init; +#endif BOOST_TEST(x1.empty()); } @@ -542,7 +578,12 @@ namespace constructor_tests { #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) UNORDERED_AUTO_TEST (test_initializer_list) { +#ifdef BOOST_UNORDERED_FOA_TESTS + boost::unordered_flat_set x1 = {2, 10, 45, -5}; +#else boost::unordered_set x1 = {2, 10, 45, -5}; +#endif + BOOST_TEST(x1.find(10) != x1.end()); BOOST_TEST(x1.find(46) == x1.end()); }