From 61516be1db7fbaf188b7f980e663ddcea863ecf1 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sun, 22 Jul 2012 20:14:20 +0000 Subject: [PATCH] Unordered: Remove use of try..catch. So that it'll work when exceptions are disabled. [SVN r79679] --- include/boost/unordered/detail/allocate.hpp | 41 +++++++++++++++++---- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/include/boost/unordered/detail/allocate.hpp b/include/boost/unordered/detail/allocate.hpp index 3385658e..ebc9993f 100644 --- a/include/boost/unordered/detail/allocate.hpp +++ b/include/boost/unordered/detail/allocate.hpp @@ -1120,17 +1120,42 @@ namespace boost { namespace unordered { namespace detail { #else + template + struct value_construct + { + typedef BOOST_DEDUCED_TYPENAME AllocTraits::allocator_type allocator; + + allocator& alloc; + T* ptr; + + value_construct(allocator& a, T* p) : alloc(a), ptr(p) + { + AllocTraits::construct(alloc, ptr, T()); + } + + void release() + { + ptr = 0; + } + + ~value_construct() + { + if (ptr) AllocTraits::destroy(alloc, ptr); + } + + private: + value_construct(value_construct const&); + value_construct& operator=(value_construct const&); + }; + template inline void construct_node(Alloc& a, T* p, BOOST_UNORDERED_EMPLACE_ARGS) { - boost::unordered::detail::allocator_traits::construct(a, p, T()); - try { - boost::unordered::detail::construct_impl( - p->value_ptr(), BOOST_UNORDERED_EMPLACE_FORWARD); - } catch(...) { - boost::unordered::detail::allocator_traits::destroy(a, p); - throw; - } + value_construct, T> + construct_guard(a, p); + boost::unordered::detail::construct_impl( + p->value_ptr(), BOOST_UNORDERED_EMPLACE_FORWARD); + construct_guard.release(); } template