Refactor drop_guard into destroy_on_exit

This commit is contained in:
Christian Mazakas
2023-03-02 15:55:56 -08:00
parent 5a5c31de35
commit 48e92afd92

View File

@ -1137,17 +1137,6 @@ union uninitialized_storage
~uninitialized_storage(){} ~uninitialized_storage(){}
}; };
template <class TypePolicy,class A,class T>
struct drop_guard
{
using type_policy=TypePolicy;
A& a;
T* p;
~drop_guard(){type_policy::destroy(a,p);};
};
/* foa::table interface departs in a number of ways from that of C++ unordered /* foa::table interface departs in a number of ways from that of C++ unordered
* associative containers because it's not for end-user consumption * associative containers because it's not for end-user consumption
* (boost::unordered_[flat|node]_[map|set]) wrappers complete it as * (boost::unordered_[flat|node]_[map|set]) wrappers complete it as
@ -1454,7 +1443,7 @@ public:
type_policy::construct(al(),p,std::forward<Args>(args)...); type_policy::construct(al(),p,std::forward<Args>(args)...);
drop_guard<type_policy,Allocator,insert_type> guard{al(),p}; destroy_on_exit<insert_type> guard{al(),p};
return emplace_impl(type_policy::move(*p)); return emplace_impl(type_policy::move(*p));
} }
@ -1658,6 +1647,16 @@ private:
bool rollback_=false; bool rollback_=false;
}; };
template <class T>
struct destroy_on_exit
{
using type_policy=TypePolicy;
Allocator &a;
T *p;
~destroy_on_exit(){type_policy::destroy(a,p);};
};
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();}