diff options
author | redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-06-25 20:54:46 +0000 |
---|---|---|
committer | redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-06-25 20:54:46 +0000 |
commit | ac4cf92ef6d50b09fde2fc83dc60a3f2d5fa9968 (patch) | |
tree | 9814c386214bbf28f714ae8aea45ac46a3ee273c /libstdc++-v3/include/experimental/any | |
parent | f933d589beb2babe9b7e79a9bd1d166572422909 (diff) | |
download | gcc-ac4cf92ef6d50b09fde2fc83dc60a3f2d5fa9968.tar.gz |
* include/Makefile.am: Add new header.
* include/Makefile.in: Regenerate.
* include/bits/allocated_ptr.h (__allocated_ptr, __allocate_guarded):
New RAII utilities for working with allocators.
* include/bits/shared_ptr_base.h (_Sp_counted_deleter): Define
__allocator_type typedef and use new __allocated_ptr type.
(_Sp_counted_ptr_inplace): Likewise.
(__shared_count::__shared_count, __shared_ptr::__shared_ptr): Use
__allocate_guarded to to simplify exception handling.
* include/experimental/any (any::_Manager_alloc::_S_alloc): Likewise.
* include/std/future (_Result_alloc::_M_destroy): Likewise.
(_Result_alloc::_S_allocate_result): Likewise.
* testsuite/20_util/shared_ptr/cons/43820_neg.cc: Adjust line number.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/creation/no_rtti.cc: New.
* testsuite/20_util/shared_ptr/creation/alloc.cc: Test allocator
with fancy pointer.
* testsuite/30_threads/promise/cons/alloc.cc: Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@211996 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include/experimental/any')
-rw-r--r-- | libstdc++-v3/include/experimental/any | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/libstdc++-v3/include/experimental/any b/libstdc++-v3/include/experimental/any index 643fc235848..8f6e372c3b1 100644 --- a/libstdc++-v3/include/experimental/any +++ b/libstdc++-v3/include/experimental/any @@ -116,8 +116,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename _Tp, typename _Alloc> struct _Manager_alloc; // creates contained object using an allocator - template<typename _Tp, typename _Alloc, typename _TpAlloc - = typename allocator_traits<_Alloc>::template rebind_alloc<_Tp>> + template<typename _Tp, typename _Alloc, + typename _TpAlloc = __alloc_rebind<_Alloc, _Tp>> using _ManagerAlloc = conditional_t<_Internal<_Tp>::value, _Manager_internal<_Tp>, _Manager_alloc<_Tp, _TpAlloc>>; @@ -501,19 +501,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _S_alloc(const _Alloc& __a, _Up&& __value) { typename _Traits::allocator_type __a2(__a); - auto __ptr = _Traits::allocate(__a2, 1); - __try - { - any::_Storage __storage; - __storage._M_ptr = std::__addressof(*__ptr); - ::new(__storage._M_ptr) _Data{__a, std::forward<_Up>(__value)}; - return __storage; - } - __catch(...) - { - _Traits::deallocate(__a2, __ptr, 1); - __throw_exception_again; - } + auto __guard = std::__allocate_guarded(__a2); + any::_Storage __storage; + __storage._M_ptr = __guard.get(); + ::new(__storage._M_ptr) _Data{__a, std::forward<_Up>(__value)}; + __guard = nullptr; + return __storage; } #endif @@ -591,11 +584,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION break; case _Op_destroy: { - using _PtrTr = pointer_traits<typename _Traits::pointer>; - typename _Traits::allocator_type __a(__ptr->_M_alloc()); - auto __alloc_ptr = _PtrTr::pointer_to(*const_cast<_Data*>(__ptr)); + using _Alloc2 = typename _Traits::allocator_type; + _Alloc2 __a(__ptr->_M_alloc()); + __allocated_ptr<_Alloc2> __guard{__a, const_cast<_Data*>(__ptr)}; __ptr->~_Data(); - _Traits::deallocate(__a, __alloc_ptr, 1); } break; } |