diff --git a/test/cfoa/assign_tests.cpp b/test/cfoa/assign_tests.cpp index f2dd2364..409e9d8d 100644 --- a/test/cfoa/assign_tests.cpp +++ b/test/cfoa/assign_tests.cpp @@ -31,7 +31,7 @@ using test::sequential; using hasher = stateful_hash; using key_equal = stateful_key_equal; -using allocator_type = stateful_allocator >; +using allocator_type = stateful_allocator2 >; using flat_map_type = boost::unordered::unordered_flat_map; @@ -847,8 +847,12 @@ namespace { check_raii_counts(); } - template void flat_map_move_assign(G gen, test::random_generator rg) + template + void flat_map_move_assign( + FlatMapType*, MapType*, G gen, test::random_generator rg) { + using alloc_type = typename MapType::allocator_type; + auto values = make_random_values(1024 * 16, [&] { return gen(rg); }); auto reference_map = boost::unordered_flat_map(values.begin(), values.end()); @@ -864,10 +868,10 @@ namespace { { raii::reset_counts(); - flat_map_type flat_map(values.begin(), values.end(), values.size(), - hasher(1), key_equal(2), allocator_type(3)); + FlatMapType flat_map(values.begin(), values.end(), values.size(), + hasher(1), key_equal(2), alloc_type(3)); - map_type map(0, hasher(2), key_equal(1), allocator_type(3)); + MapType map(0, hasher(2), key_equal(1), alloc_type(3)); BOOST_TEST(flat_map.get_allocator() == map.get_allocator()); @@ -893,10 +897,10 @@ namespace { { raii::reset_counts(); - map_type map(values.begin(), values.end(), values.size(), hasher(1), - key_equal(2), allocator_type(3)); + MapType map(values.begin(), values.end(), values.size(), hasher(1), + key_equal(2), alloc_type(3)); - flat_map_type flat_map(0, hasher(2), key_equal(1), allocator_type(3)); + FlatMapType flat_map(0, hasher(2), key_equal(1), alloc_type(3)); BOOST_TEST(flat_map.get_allocator() == map.get_allocator()); @@ -920,10 +924,10 @@ namespace { { raii::reset_counts(); - flat_map_type flat_map(values.begin(), values.end(), values.size(), - hasher(1), key_equal(2), allocator_type(3)); + FlatMapType flat_map(values.begin(), values.end(), values.size(), + hasher(1), key_equal(2), alloc_type(3)); - map_type map(0, hasher(2), key_equal(1), allocator_type(4)); + MapType map(0, hasher(2), key_equal(1), alloc_type(4)); BOOST_TEST(flat_map.get_allocator() != map.get_allocator()); @@ -950,10 +954,10 @@ namespace { { raii::reset_counts(); - map_type map(values.begin(), values.end(), values.size(), hasher(1), - key_equal(2), allocator_type(3)); + MapType map(values.begin(), values.end(), values.size(), hasher(1), + key_equal(2), alloc_type(3)); - flat_map_type flat_map(0, hasher(2), key_equal(1), allocator_type(4)); + FlatMapType flat_map(0, hasher(2), key_equal(1), alloc_type(4)); BOOST_TEST(flat_map.get_allocator() != map.get_allocator()); @@ -994,8 +998,27 @@ UNORDERED_TEST( ((init_type_generator)) ((default_generator)(sequential)(limited_range))) +boost::unordered::unordered_flat_map > >* flat_map_plain; +boost::unordered::unordered_flat_map > >* flat_map_fancy; + +boost::unordered::concurrent_flat_map > >* map_plain; +boost::unordered::concurrent_flat_map > >* map_fancy; + UNORDERED_TEST( flat_map_move_assign, + ((flat_map_plain)) + ((map_plain)) + ((init_type_generator)) + ((default_generator)(sequential)(limited_range))) + +UNORDERED_TEST( + flat_map_move_assign, + ((flat_map_fancy)) + ((map_fancy)) ((init_type_generator)) ((default_generator)(sequential)(limited_range))) // clang-format on diff --git a/test/cfoa/helpers.hpp b/test/cfoa/helpers.hpp index a4db7e44..79b91bb0 100644 --- a/test/cfoa/helpers.hpp +++ b/test/cfoa/helpers.hpp @@ -123,6 +123,27 @@ struct stateful_key_equal } }; +template struct cfoa_ptr +{ +private: + template friend struct stateful_allocator2; + + T* p_ = nullptr; + + cfoa_ptr(T* p) : p_(p) {} + +public: + using element_type = T; + + cfoa_ptr() = default; + cfoa_ptr(std::nullptr_t) : p_(nullptr){}; + template using rebind = cfoa_ptr; + + T* operator->() const noexcept { return p_; } + + static cfoa_ptr pointer_to(element_type& r) { return {std::addressof(r)}; } +}; + template struct stateful_allocator { int x_ = -1; @@ -151,6 +172,36 @@ template struct stateful_allocator bool operator!=(stateful_allocator const& rhs) const { return x_ != rhs.x_; } }; +template struct stateful_allocator2 +{ + + int x_ = -1; + + using value_type = T; + using pointer = cfoa_ptr; + + stateful_allocator2() = default; + stateful_allocator2(stateful_allocator2 const&) = default; + stateful_allocator2(stateful_allocator2&&) = default; + + stateful_allocator2(int const x) : x_{x} {} + + template + stateful_allocator2(stateful_allocator2 const& rhs) : x_{rhs.x_} + { + } + + pointer allocate(std::size_t n) + { + return {static_cast(::operator new(n * sizeof(T)))}; + } + + void deallocate(pointer p, std::size_t) { ::operator delete(p.p_); } + + bool operator==(stateful_allocator2 const& rhs) const { return x_ == rhs.x_; } + bool operator!=(stateful_allocator2 const& rhs) const { return x_ != rhs.x_; } +}; + struct raii { static std::atomic default_constructor;