diff --git a/include/boost/unordered/unordered_node_set.hpp b/include/boost/unordered/unordered_node_set.hpp index 9655a767..0387bdf6 100644 --- a/include/boost/unordered/unordered_node_set.hpp +++ b/include/boost/unordered/unordered_node_set.hpp @@ -39,30 +39,15 @@ namespace boost { using init_type = Key; using value_type = Key; - // struct element_type - // { - // value_type* p; - // }; - - // static value_type& value_from(element_type x) { return *x.p; } + static Key const& extract(value_type const& key) { return key; } +#if 1 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 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) { @@ -70,35 +55,20 @@ namespace boost { 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, 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, 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) @@ -115,20 +85,9 @@ namespace boost { } } - // 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) { + if (*p) { boost::allocator_destroy(al, *p); boost::allocator_deallocate(al, boost::pointer_traits< @@ -136,13 +95,63 @@ namespace boost { 1); } } +#else + struct element_type + { + value_type* p; + }; + + static value_type& value_from(element_type x) { return *x.p; } + static Key const& extract(element_type k) { return *k.p; } + static element_type&& move(element_type& x) { return std::move(x); } + + template + static void construct(A& al, element_type* p, element_type const& copy) + { + construct(al, p, *copy.p); + } + + template + static void construct( + Allocator&, element_type* p, element_type&& x) noexcept + { + p->p = x.p; + x.p = nullptr; + } + + 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 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); + } + } +#endif }; } // namespace detail template class unordered_node_set { - using set_types = detail::flat_set_types; + using set_types = detail::node_set_types; using table_type = detail::foa::table