diff --git a/include/boost/unordered/detail/foa.hpp b/include/boost/unordered/detail/foa.hpp index 8b22f0d7..6cca237e 100644 --- a/include/boost/unordered/detail/foa.hpp +++ b/include/boost/unordered/detail/foa.hpp @@ -1499,9 +1499,8 @@ public: void merge(table& x) { x.for_all_elements([&,this](group_type* pg,unsigned int n,element_type* p){ - if(emplace_impl(type_policy::move(*p)).second){ - x.erase(iterator{pg,n,p}); - } + erase_on_exit e{x,{pg,n,p}}; + if(!emplace_impl(type_policy::move(*p)).second)e.rollback(); }); } @@ -1569,6 +1568,17 @@ private: table& x; }; + struct erase_on_exit + { + ~erase_on_exit(){if(!rollback_)x.erase(it);} + + void rollback(){rollback_=true;} + + table& x; + iterator it; + bool rollback_=false; + }; + Hash& h(){return hash_base::get();} const Hash& h()const{return hash_base::get();} Pred& pred(){return pred_base::get();}