diff --git a/include/boost/unordered/detail/foa.hpp b/include/boost/unordered/detail/foa.hpp index 209f063b..82ebc4cb 100644 --- a/include/boost/unordered/detail/foa.hpp +++ b/include/boost/unordered/detail/foa.hpp @@ -829,6 +829,11 @@ table:empty_value,empty_value,empty_value public: using key_type=typename type_policy::key_type; using init_type=typename type_policy::init_type; + +private: + using moved_type=typename type_policy::moved_type; + +public: using value_type=typename type_policy::value_type; private: @@ -995,7 +1000,7 @@ public: */ x.for_all_elements([this](value_type* p){ - unchecked_insert(std::move(*p)); + unchecked_insert(type_policy::move(*p)); }); } BOOST_CATCH(...){ @@ -1221,6 +1226,17 @@ private: return type_policy::extract(x); } + template< + bool dependent_value=false, + typename std::enable_if< + has_different_init_type||dependent_value>::type* =nullptr + > + static inline auto key_from(const moved_type& x) + ->decltype(type_policy::extract(x)) + { + return type_policy::extract(x); + } + static inline auto key_from(const value_type& x) ->decltype(type_policy::extract(x)) { @@ -1361,9 +1377,8 @@ private: void nosize_transfer_element(value_type* p,const arrays_type& arrays_) { auto hash=h()(key_from(*p)); - type_policy::move_parts_to( - *p, - bind_unchecked_emplace_at{this,arrays_,position_for(hash,arrays_),hash}); + nosize_unchecked_emplace_at( + arrays_,position_for(hash,arrays_),hash,type_policy::move(*p)); destroy_element(p); } @@ -1429,21 +1444,6 @@ private: } #endif - struct bind_unchecked_emplace_at - { - template - iterator operator()(Args&&... args)const - { - return this_->nosize_unchecked_emplace_at( - arrays,pos0,hash,std::forward(args)...); - } - - table* this_; - const arrays_type& arrays; - std::size_t pos0; - std::size_t hash; - }; - template void for_all_elements(F f)const { diff --git a/include/boost/unordered/unordered_flat_map.hpp b/include/boost/unordered/unordered_flat_map.hpp index 85c919d8..64175639 100644 --- a/include/boost/unordered/unordered_flat_map.hpp +++ b/include/boost/unordered/unordered_flat_map.hpp @@ -30,14 +30,16 @@ namespace boost { { using key_type = Key; using init_type = std::pair; + using moved_type = std::pair; using value_type = std::pair; static Key const& extract(init_type const& kv) { return kv.first; } static Key const& extract(value_type const& kv) { return kv.first; } + static Key const& extract(moved_type const& kv) { return kv.first; } - template static void move_parts_to(value_type& x, F f) + static moved_type move(value_type& x) { // TODO: we probably need to launder here - f(std::move(const_cast(x.first)), std::move(x.second)); + return {std::move(const_cast(x.first)), std::move(x.second)}; } }; diff --git a/include/boost/unordered/unordered_flat_set.hpp b/include/boost/unordered/unordered_flat_set.hpp index f01ea751..9b7f366d 100644 --- a/include/boost/unordered/unordered_flat_set.hpp +++ b/include/boost/unordered/unordered_flat_set.hpp @@ -30,13 +30,10 @@ namespace boost { { using key_type = Key; using init_type = Key; + using moved_type = Key; using value_type = Key; static Key const& extract(value_type const& key) { return key; } - - template static void move_parts_to(value_type& x, F f) - { - f(std::move(x)); - } + static Key&& move(value_type& x) { return std::move(x); } }; using table_type = detail::foa::table