Refactor erase_on_exit to use a const_iterator so callsites can avoid a const cast

This commit is contained in:
Christian Mazakas
2023-02-19 21:18:56 -08:00
parent f405fa9118
commit a1adacdfe2

View File

@ -1509,7 +1509,7 @@ public:
element_type extract(const_iterator pos) element_type extract(const_iterator pos)
{ {
BOOST_ASSERT(pos!=end()); BOOST_ASSERT(pos!=end());
erase_on_exit e{*this,iterator{const_iterator_cast_tag{},pos}}; erase_on_exit e{*this,pos};
(void)e; (void)e;
return std::move(*pos.p); return std::move(*pos.p);
} }
@ -1599,14 +1599,14 @@ private:
struct erase_on_exit struct erase_on_exit
{ {
erase_on_exit(table& x_,iterator it_):x{x_},it{it_}{} erase_on_exit(table& x_,const_iterator it_):x{x_},it{it_}{}
~erase_on_exit(){if(!rollback_)x.erase(it);} ~erase_on_exit(){if(!rollback_)x.erase(it);}
void rollback(){rollback_=true;} void rollback(){rollback_=true;}
table& x; table& x;
iterator it; const_iterator it;
bool rollback_=false; bool rollback_=false;
}; };
Hash& h(){return hash_base::get();} Hash& h(){return hash_base::get();}