fixed bug with dangling moved element on throwing rehash during merge

This commit is contained in:
joaquintides
2023-01-27 11:20:36 +01:00
committed by Christian Mazakas
parent 8da44f4f46
commit 53e4531295

View File

@ -1499,9 +1499,8 @@ public:
void merge(table<TypePolicy,Hash2,Pred2,Allocator>& x) void merge(table<TypePolicy,Hash2,Pred2,Allocator>& x)
{ {
x.for_all_elements([&,this](group_type* pg,unsigned int n,element_type* p){ x.for_all_elements([&,this](group_type* pg,unsigned int n,element_type* p){
if(emplace_impl(type_policy::move(*p)).second){ erase_on_exit e{x,{pg,n,p}};
x.erase(iterator{pg,n,p}); if(!emplace_impl(type_policy::move(*p)).second)e.rollback();
}
}); });
} }
@ -1569,6 +1568,17 @@ private:
table& x; 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();} Hash& h(){return hash_base::get();}
const Hash& h()const{return hash_base::get();} const Hash& h()const{return hash_base::get();}
Pred& pred(){return pred_base::get();} Pred& pred(){return pred_base::get();}