Replace usage of rote try-catch with corresponding Boost versions

This commit is contained in:
Christian Mazakas
2023-01-31 10:32:06 -08:00
parent 16099478db
commit a46220986f
2 changed files with 15 additions and 16 deletions

View File

@ -86,31 +86,26 @@ namespace boost {
template <class A> template <class A>
static void construct(A& al, element_type* p, element_type const& copy) static void construct(A& al, element_type* p, element_type const& copy)
{ {
p->p = boost::to_address(boost::allocator_allocate(al, 1)); construct(al, p, *copy.p);
try {
boost::allocator_construct(al, p->p, *copy.p);
} catch (...) {
boost::allocator_deallocate(al,
boost::pointer_traits<
typename boost::allocator_pointer<A>::type>::pointer_to(*p->p),
1);
throw;
}
} }
template <class A, class... Args> template <class A, class... Args>
static void construct(A& al, element_type* p, Args&&... args) static void construct(A& al, element_type* p, Args&&... args)
{ {
p->p = boost::to_address(boost::allocator_allocate(al, 1)); p->p = boost::to_address(boost::allocator_allocate(al, 1));
try { BOOST_TRY
{
boost::allocator_construct(al, p->p, std::forward<Args>(args)...); boost::allocator_construct(al, p->p, std::forward<Args>(args)...);
} catch (...) { }
BOOST_CATCH(...)
{
boost::allocator_deallocate(al, boost::allocator_deallocate(al,
boost::pointer_traits< boost::pointer_traits<
typename boost::allocator_pointer<A>::type>::pointer_to(*p->p), typename boost::allocator_pointer<A>::type>::pointer_to(*p->p),
1); 1);
throw; BOOST_RETHROW
} }
BOOST_CATCH_END
} }
template <class A> static void destroy(A& al, element_type* p) noexcept template <class A> static void destroy(A& al, element_type* p) noexcept

View File

@ -76,15 +76,19 @@ namespace boost {
static void construct(A& al, element_type* p, Args&&... args) static void construct(A& al, element_type* p, Args&&... args)
{ {
p->p = boost::to_address(boost::allocator_allocate(al, 1)); p->p = boost::to_address(boost::allocator_allocate(al, 1));
try { BOOST_TRY
{
boost::allocator_construct(al, p->p, std::forward<Args>(args)...); boost::allocator_construct(al, p->p, std::forward<Args>(args)...);
} catch (...) { }
BOOST_CATCH(...)
{
boost::allocator_deallocate(al, boost::allocator_deallocate(al,
boost::pointer_traits< boost::pointer_traits<
typename boost::allocator_pointer<A>::type>::pointer_to(*p->p), typename boost::allocator_pointer<A>::type>::pointer_to(*p->p),
1); 1);
throw; BOOST_RETHROW
} }
BOOST_CATCH_END
} }
template <class A> static void destroy(A& al, element_type* p) noexcept template <class A> static void destroy(A& al, element_type* p) noexcept