Fix exception safety in aged containers

This commit is contained in:
Vinnie Falco
2014-08-14 13:01:07 -07:00
parent fe9d77734f
commit 97d87dff09
2 changed files with 38 additions and 8 deletions

View File

@@ -389,11 +389,26 @@ private:
template <class... Args>
element* new_element (Args&&... args)
{
element* const p (
ElementAllocatorTraits::allocate (m_config.alloc(), 1));
struct Deleter
{
std::reference_wrapper <ElementAllocator> a_;
Deleter (ElementAllocator& a)
: a_(a)
{
}
void
operator()(element* p)
{
ElementAllocatorTraits::deallocate (a_.get(), p, 1);
}
};
std::unique_ptr <element, Deleter> p (ElementAllocatorTraits::allocate (
m_config.alloc(), 1), Deleter(m_config.alloc()));
ElementAllocatorTraits::construct (m_config.alloc(),
p, clock().now(), std::forward <Args> (args)...);
return p;
p.get(), clock().now(), std::forward <Args> (args)...);
return p.release();
}
void delete_element (element const* p)

View File

@@ -577,11 +577,26 @@ private:
template <class... Args>
element* new_element (Args&&... args)
{
element* const p (
ElementAllocatorTraits::allocate (m_config.alloc(), 1));
struct Deleter
{
std::reference_wrapper <ElementAllocator> a_;
Deleter (ElementAllocator& a)
: a_(a)
{
}
void
operator()(element* p)
{
ElementAllocatorTraits::deallocate (a_.get(), p, 1);
}
};
std::unique_ptr <element, Deleter> p (ElementAllocatorTraits::allocate (
m_config.alloc(), 1), Deleter(m_config.alloc()));
ElementAllocatorTraits::construct (m_config.alloc(),
p, clock().now(), std::forward <Args> (args)...);
return p;
p.get(), clock().now(), std::forward <Args> (args)...);
return p.release();
}
void delete_element (element const* p)