From 1e61423eac8fb9fd2c00640f9e3f7667a400fddd Mon Sep 17 00:00:00 2001 From: Christian Mazakas Date: Wed, 11 Jan 2023 13:02:04 -0800 Subject: [PATCH] Prove relevance of strong typedef for node-based foa containers --- .../boost/unordered/unordered_node_set.hpp | 61 ++----------------- test/unordered/insert_tests.cpp | 7 ++- 2 files changed, 9 insertions(+), 59 deletions(-) diff --git a/include/boost/unordered/unordered_node_set.hpp b/include/boost/unordered/unordered_node_set.hpp index 56325162..5457f40f 100644 --- a/include/boost/unordered/unordered_node_set.hpp +++ b/include/boost/unordered/unordered_node_set.hpp @@ -40,65 +40,15 @@ namespace boost { static Key const& extract(value_type const& key) { return key; } -#if 0 - using element_type = value_type*; - static value_type& value_from(element_type& x) { return *x; } - - static Key const& extract(element_type k) { return *k; } - static element_type&& move(element_type& x) { return std::move(x); } - - template - static void construct(A&, element_type* p, element_type&& x) - { - *p = x; - x = nullptr; - } - - template - static void construct(A& al, element_type* p, element_type const& x) - { - *p = boost::to_address(boost::allocator_allocate(al, 1)); - try { - boost::allocator_construct(al, *p, *x); - } catch (...) { - boost::allocator_deallocate(al, - boost::pointer_traits< - typename boost::allocator_pointer::type>::pointer_to(**p), - 1); - throw; - } - } - - template - static void construct(A& al, element_type* p, Args&&... args) - { - *p = boost::to_address(boost::allocator_allocate(al, 1)); - try { - boost::allocator_construct(al, *p, std::forward(args)...); - } catch (...) { - boost::allocator_deallocate(al, - boost::pointer_traits< - typename boost::allocator_pointer::type>::pointer_to(**p), - 1); - throw; - } - } - - template static void destroy(A& al, element_type* p) noexcept - { - if (*p) { - boost::allocator_destroy(al, *p); - boost::allocator_deallocate(al, - boost::pointer_traits< - typename boost::allocator_pointer::type>::pointer_to(**p), - 1); - } - } -#else struct element_type { value_type* p; + /* + * we use a defined copy constructor here so the type is no longer + * trivially copy-constructible which inhibits our memcpy + * optimizations when copying the tables + */ element_type() : p(nullptr) {} element_type(element_type const& rhs) : p(rhs.p) {} }; @@ -146,7 +96,6 @@ namespace boost { 1); } } -#endif }; } // namespace detail diff --git a/test/unordered/insert_tests.cpp b/test/unordered/insert_tests.cpp index 3e0bce7d..446e286a 100644 --- a/test/unordered/insert_tests.cpp +++ b/test/unordered/insert_tests.cpp @@ -701,7 +701,7 @@ namespace insert_tests { pointer_constructible(int x_) : x(x_) {} pointer_constructible(pointer_constructible const& p) : x(p.x) {} pointer_constructible(pointer_constructible* const&) : x(-1) {} - pointer_constructible(BOOST_RV_REF(pointer_constructible*)) : x(-2) {} + pointer_constructible(BOOST_RV_REF(pointer_constructible*)) : x(-1) {} }; struct pointer_constructible_hash @@ -733,11 +733,12 @@ namespace insert_tests { pointer_constructible_equal_to, test::allocator1 > set, set2; - pointer_constructible pc(1337), *addr_pc = &pc; + pointer_constructible pc(1337); + pointer_constructible* const addr_pc = &pc; set.insert(pc); // 1337 - set.insert(addr_pc); // -1 set.insert(&pc); // -1 + set.insert(addr_pc); // -1 BOOST_TEST_EQ(set.size(), 2u); BOOST_TEST(set.find(pc) != set.end());