From bce898165c5ca4a15a7c1ea0a12acad00415eb17 Mon Sep 17 00:00:00 2001 From: Christian Mazakas Date: Mon, 9 Jan 2023 15:45:25 -0800 Subject: [PATCH] Add transparent insert, show we don't need a strong typedef --- .../boost/unordered/unordered_node_set.hpp | 115 +++++++++++++----- 1 file changed, 86 insertions(+), 29 deletions(-) diff --git a/include/boost/unordered/unordered_node_set.hpp b/include/boost/unordered/unordered_node_set.hpp index 582c3360..9655a767 100644 --- a/include/boost/unordered/unordered_node_set.hpp +++ b/include/boost/unordered/unordered_node_set.hpp @@ -39,61 +39,100 @@ namespace boost { using init_type = Key; using value_type = Key; - struct element_type - { - value_type* p; - }; + // struct element_type + // { + // value_type* p; + // }; - static value_type& value_from(element_type x) { return *x.p; } + // static value_type& value_from(element_type x) { return *x.p; } + + using element_type = value_type*; + static value_type& value_from(element_type x) { return *x; } static Key const& extract(value_type const& key) { return key; } - static Key const& extract(element_type k) { return *k.p; } + // static Key const& extract(element_type k) { return *k.p; } + // static element_type&& move(element_type& x) { return std::move(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->p = x.p; + // x.p = nullptr; + // } + template static void construct(A&, element_type* p, element_type&& x) { - p->p = x.p; - x.p = nullptr; + *p = x; + x = nullptr; } - template - static void construct(A& al, element_type* p, element_type const& copy) - { - p->p = boost::to_address(boost::allocator_allocate(al, 1)); - try { - boost::allocator_construct(al, p->p, *copy.p); - } catch (...) { - boost::allocator_deallocate(al, - boost::pointer_traits< - typename boost::allocator_pointer::type>::pointer_to(*p->p), - 1); - throw; - } - } + // template + // static void construct(A& al, element_type* p, element_type const& copy) + // { + // p->p = boost::to_address(boost::allocator_allocate(al, 1)); + // try { + // boost::allocator_construct(al, p->p, *copy.p); + // } catch (...) { + // boost::allocator_deallocate(al, + // boost::pointer_traits< + // typename boost::allocator_pointer::type>::pointer_to(*p->p), + // 1); + // throw; + // } + // } + + // template + // static void construct(A& al, element_type* p, Args&&... args) + // { + // p->p = boost::to_address(boost::allocator_allocate(al, 1)); + // try { + // boost::allocator_construct(al, p->p, std::forward(args)...); + // } catch (...) { + // boost::allocator_deallocate(al, + // boost::pointer_traits< + // typename boost::allocator_pointer::type>::pointer_to(*p->p), + // 1); + // throw; + // } + // } template static void construct(A& al, element_type* p, Args&&... args) { - p->p = boost::to_address(boost::allocator_allocate(al, 1)); + *p = boost::to_address(boost::allocator_allocate(al, 1)); try { - boost::allocator_construct(al, p->p, std::forward(args)...); + boost::allocator_construct(al, *p, std::forward(args)...); } catch (...) { boost::allocator_deallocate(al, boost::pointer_traits< - typename boost::allocator_pointer::type>::pointer_to(*p->p), + typename boost::allocator_pointer::type>::pointer_to(**p), 1); throw; } } + // template static void destroy(A& al, element_type* p) noexcept + // { + // if (p->p) { + // boost::allocator_destroy(al, p->p); + // boost::allocator_deallocate(al, + // boost::pointer_traits< + // typename boost::allocator_pointer::type>::pointer_to(*p->p), + // 1); + // } + // } + template static void destroy(A& al, element_type* p) noexcept { - if (p->p) { - boost::allocator_destroy(al, p->p); + if (p) { + boost::allocator_destroy(al, *p); boost::allocator_deallocate(al, boost::pointer_traits< - typename boost::allocator_pointer::type>::pointer_to(*p->p), + typename boost::allocator_pointer::type>::pointer_to(**p), 1); } } @@ -103,7 +142,7 @@ namespace boost { template class unordered_node_set { - using set_types = detail::node_set_types; + using set_types = detail::flat_set_types; using table_type = detail::foa::table + BOOST_FORCEINLINE typename std::enable_if< + detail::transparent_non_iterable::value, + std::pair >::type + insert(K&& k) + { + return table_.try_emplace(std::forward(k)); + } + BOOST_FORCEINLINE iterator insert(const_iterator, value_type const& value) { return table_.insert(value).first; @@ -304,6 +352,15 @@ namespace boost { return table_.insert(std::move(value)).first; } + template + BOOST_FORCEINLINE typename std::enable_if< + detail::transparent_non_iterable::value, + iterator>::type + insert(const_iterator, K&& k) + { + return table_.try_emplace(std::forward(k)).first; + } + template void insert(InputIterator first, InputIterator last) {