Index: include/memory =================================================================== --- include/memory +++ include/memory @@ -3657,8 +3657,14 @@ class __shared_ptr_emplace : public __shared_weak_count { +private: __compressed_pair<_Alloc, _Tp> __data_; + + virtual void __on_zero_shared() _NOEXCEPT; + virtual void __on_zero_shared_weak() _NOEXCEPT; + public: + #ifndef _LIBCPP_HAS_NO_VARIADICS _LIBCPP_INLINE_VISIBILITY @@ -3694,10 +3700,6 @@ #endif // _LIBCPP_HAS_NO_VARIADICS -private: - virtual void __on_zero_shared() _NOEXCEPT; - virtual void __on_zero_shared_weak() _NOEXCEPT; -public: _LIBCPP_INLINE_VISIBILITY _Tp* get() _NOEXCEPT {return _VSTD::addressof(__data_.second());} }; @@ -3745,7 +3747,7 @@ typedef weak_ptr<_Tp> weak_type; #endif private: - element_type* __ptr_; + element_type* __ptr_; __shared_weak_count* __cntrl_; struct __nat {int __for_bool_;}; @@ -3793,45 +3795,34 @@ typename enable_if::value, __nat>::type = __nat()); #endif #endif + + template +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + shared_ptr(unique_ptr<_Yp, _Dp&>&& __r, +#else + shared_ptr(unique_ptr<_Yp, _Dp&> __r, +#endif + typename enable_if + < + !is_array<_Yp>::value && + is_convertible::pointer, + element_type*>::value, + __nat + >::type = __nat()); + + template #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - template - shared_ptr(unique_ptr<_Yp, _Dp>&&, - typename enable_if - < - !is_lvalue_reference<_Dp>::value && - !is_array<_Yp>::value && - is_convertible::pointer, element_type*>::value, - __nat - >::type = __nat()); - template - shared_ptr(unique_ptr<_Yp, _Dp>&&, - typename enable_if - < - is_lvalue_reference<_Dp>::value && - !is_array<_Yp>::value && - is_convertible::pointer, element_type*>::value, - __nat - >::type = __nat()); -#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES - template - shared_ptr(unique_ptr<_Yp, _Dp>, - typename enable_if - < - !is_lvalue_reference<_Dp>::value && - !is_array<_Yp>::value && - is_convertible::pointer, element_type*>::value, - __nat - >::type = __nat()); - template - shared_ptr(unique_ptr<_Yp, _Dp>, - typename enable_if - < - is_lvalue_reference<_Dp>::value && - !is_array<_Yp>::value && - is_convertible::pointer, element_type*>::value, - __nat - >::type = __nat()); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + shared_ptr(unique_ptr<_Yp, _Dp>&& __r, +#else + shared_ptr(unique_ptr<_Yp, _Dp> __r, +#endif + typename enable_if + < + !is_array<_Yp>::value && + is_convertible::pointer, + element_type*>::value, + __nat + >::type = __nat()); ~shared_ptr(); @@ -3959,48 +3950,16 @@ : nullptr);} #endif // _LIBCPP_NO_RTTI -#ifndef _LIBCPP_HAS_NO_VARIADICS - - template - static - shared_ptr<_Tp> - make_shared(_Args&& ...__args); - - template - static - shared_ptr<_Tp> - allocate_shared(const _Alloc& __a, _Args&& ...__args); - -#else // _LIBCPP_HAS_NO_VARIADICS - - static shared_ptr<_Tp> make_shared(); - - template - static shared_ptr<_Tp> make_shared(_A0&); - - template - static shared_ptr<_Tp> make_shared(_A0&, _A1&); - - template - static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&); - - template - static shared_ptr<_Tp> - allocate_shared(const _Alloc& __a); - - template - static shared_ptr<_Tp> - allocate_shared(const _Alloc& __a, _A0& __a0); - - template - static shared_ptr<_Tp> - allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1); - - template - static shared_ptr<_Tp> - allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2); - -#endif // _LIBCPP_HAS_NO_VARIADICS + template + static shared_ptr<_Tp> + __create_with_cntrl_block(_Yp* __p, _CntrlBlk* __cntrl) + { + shared_ptr<_Tp> __r; + __r.__ptr_ = __p; + __r.__cntrl_ = __cntrl; + __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); + return __r; + } private: template ::value> @@ -4036,6 +3995,52 @@ template friend class _LIBCPP_TEMPLATE_VIS shared_ptr; template friend class _LIBCPP_TEMPLATE_VIS weak_ptr; + + template, + class _Alloc = typename __shared_ptr_default_allocator<_Yp>::type> + static __shared_weak_count* + __allocate_shared(_Yp* __p, _Deleter __d = _Deleter {}, _Alloc __a = _Alloc {}) + { + try { + typedef __shared_ptr_pointer<_Yp*, _Deleter, _Alloc> _CT; + typedef typename __allocator_traits_rebind<_Alloc, _CT>::type _A2; + typedef __allocator_destructor<_A2> _D2; + + _A2 __a2(__a); + unique_ptr<_CT, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); + + ::new(static_cast(_VSTD::addressof(*__hold2.get()))) + _CT(__p, __d, __a); + + return _VSTD::addressof(*__hold2.release()); + } catch (...) { + __d(__p); + throw; + } + } + + template, + class _Alloc = typename __shared_ptr_default_allocator<_Tp>::type> + static __shared_weak_count* + __allocate_shared(nullptr_t __p, _Deleter __d = _Deleter {}, _Alloc __a = _Alloc {}) + { + try { + typedef __shared_ptr_pointer<_Tp*, _Deleter, _Alloc> _CT; + typedef typename __allocator_traits_rebind<_Alloc, _CT>::type _A2; + typedef __allocator_destructor<_A2> _D2; + + _A2 __a2(__a); + unique_ptr<_CT, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); + + ::new(static_cast(_VSTD::addressof(*__hold2.get()))) + _CT(__p, __d, __a); + + return _VSTD::addressof(*__hold2.release()); + } catch (...) { + __d(__p); + throw; + } + } }; @@ -4044,30 +4049,22 @@ _LIBCPP_CONSTEXPR shared_ptr<_Tp>::shared_ptr() _NOEXCEPT : __ptr_(0), - __cntrl_(0) -{ -} + __cntrl_(0) {} template inline _LIBCPP_CONSTEXPR shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT : __ptr_(0), - __cntrl_(0) -{ -} + __cntrl_(0) {} template template shared_ptr<_Tp>::shared_ptr(_Yp* __p, typename enable_if::value, __nat>::type) - : __ptr_(__p) + : __ptr_(__p), + __cntrl_(__allocate_shared(__p)) { - unique_ptr<_Yp> __hold(__p); - typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; - typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, _AllocT > _CntrlBlk; - __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), _AllocT()); - __hold.release(); __enable_weak_this(__p, __p); } @@ -4075,103 +4072,33 @@ template shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, typename enable_if::value, __nat>::type) - : __ptr_(__p) + : __ptr_(__p), + __cntrl_(__allocate_shared(__p, __d)) { -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_NO_EXCEPTIONS - typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; - typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk; - __cntrl_ = new _CntrlBlk(__p, __d, _AllocT()); - __enable_weak_this(__p, __p); -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - __d(__p); - throw; - } -#endif // _LIBCPP_NO_EXCEPTIONS + __enable_weak_this(__p, __p); } template template shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d) - : __ptr_(0) -{ -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_NO_EXCEPTIONS - typedef typename __shared_ptr_default_allocator<_Tp>::type _AllocT; - typedef __shared_ptr_pointer _CntrlBlk; - __cntrl_ = new _CntrlBlk(__p, __d, _AllocT()); -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - __d(__p); - throw; - } -#endif // _LIBCPP_NO_EXCEPTIONS -} + : __ptr_(0), + __cntrl_(__allocate_shared(__p, __d)) {} template template shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a, typename enable_if::value, __nat>::type) - : __ptr_(__p) + : __ptr_(__p), + __cntrl_(__allocate_shared(__p, __d, __a)) { -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_NO_EXCEPTIONS - typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk; - typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; - typedef __allocator_destructor<_A2> _D2; - _A2 __a2(__a); - unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); - ::new(static_cast(_VSTD::addressof(*__hold2.get()))) - _CntrlBlk(__p, __d, __a); - __cntrl_ = _VSTD::addressof(*__hold2.release()); - __enable_weak_this(__p, __p); -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - __d(__p); - throw; - } -#endif // _LIBCPP_NO_EXCEPTIONS + __enable_weak_this(__p, __p); } template template shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a) - : __ptr_(0) -{ -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_NO_EXCEPTIONS - typedef __shared_ptr_pointer _CntrlBlk; - typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; - typedef __allocator_destructor<_A2> _D2; - _A2 __a2(__a); - unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); - ::new(static_cast(_VSTD::addressof(*__hold2.get()))) - _CntrlBlk(__p, __d, __a); - __cntrl_ = _VSTD::addressof(*__hold2.release()); -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - __d(__p); - throw; - } -#endif // _LIBCPP_NO_EXCEPTIONS -} + : __ptr_(0), + __cntrl_(__allocate_shared(__p, __d, __a)) {} template template @@ -4255,15 +4182,15 @@ template template #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES -shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r, +shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp&>&& __r, #else -shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r, +shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp&> __r, #endif typename enable_if < - !is_lvalue_reference<_Dp>::value && !is_array<_Yp>::value && - is_convertible::pointer, element_type*>::value, + is_convertible::pointer, + element_type*>::value, __nat >::type) : __ptr_(__r.get()) @@ -4275,8 +4202,10 @@ #endif { typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; - typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk; - __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), _AllocT()); + typedef __shared_ptr_pointer<_Yp*, + reference_wrapper::type>, + _AllocT > _CntrlBlk; + __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), _AllocT()); __enable_weak_this(__r.get(), __r.get()); } __r.release(); @@ -4291,9 +4220,9 @@ #endif typename enable_if < - is_lvalue_reference<_Dp>::value && !is_array<_Yp>::value && - is_convertible::pointer, element_type*>::value, + is_convertible::pointer, + element_type*>::value, __nat >::type) : __ptr_(__r.get()) @@ -4305,215 +4234,13 @@ #endif { typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; - typedef __shared_ptr_pointer<_Yp*, - reference_wrapper::type>, - _AllocT > _CntrlBlk; - __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), _AllocT()); + typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk; + __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), _AllocT()); __enable_weak_this(__r.get(), __r.get()); } __r.release(); } -#ifndef _LIBCPP_HAS_NO_VARIADICS - -template -template -shared_ptr<_Tp> -shared_ptr<_Tp>::make_shared(_Args&& ...__args) -{ - static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in make_shared" ); - typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; - typedef allocator<_CntrlBlk> _A2; - typedef __allocator_destructor<_A2> _D2; - _A2 __a2; - unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); - ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...); - shared_ptr<_Tp> __r; - __r.__ptr_ = __hold2.get()->get(); - __r.__cntrl_ = __hold2.release(); - __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); - return __r; -} - -template -template -shared_ptr<_Tp> -shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args) -{ - static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in allocate_shared" ); - typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; - typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; - typedef __allocator_destructor<_A2> _D2; - _A2 __a2(__a); - unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); - ::new(static_cast(_VSTD::addressof(*__hold2.get()))) - _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...); - shared_ptr<_Tp> __r; - __r.__ptr_ = __hold2.get()->get(); - __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); - __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); - return __r; -} - -#else // _LIBCPP_HAS_NO_VARIADICS - -template -shared_ptr<_Tp> -shared_ptr<_Tp>::make_shared() -{ - static_assert((is_constructible<_Tp>::value), "Can't construct object in make_shared" ); - typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; - typedef allocator<_CntrlBlk> _Alloc2; - typedef __allocator_destructor<_Alloc2> _D2; - _Alloc2 __alloc2; - unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); - ::new(__hold2.get()) _CntrlBlk(__alloc2); - shared_ptr<_Tp> __r; - __r.__ptr_ = __hold2.get()->get(); - __r.__cntrl_ = __hold2.release(); - __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); - return __r; -} - -template -template -shared_ptr<_Tp> -shared_ptr<_Tp>::make_shared(_A0& __a0) -{ - static_assert((is_constructible<_Tp, _A0>::value), "Can't construct object in make_shared" ); - typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; - typedef allocator<_CntrlBlk> _Alloc2; - typedef __allocator_destructor<_Alloc2> _D2; - _Alloc2 __alloc2; - unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); - ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0); - shared_ptr<_Tp> __r; - __r.__ptr_ = __hold2.get()->get(); - __r.__cntrl_ = __hold2.release(); - __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); - return __r; -} - -template -template -shared_ptr<_Tp> -shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1) -{ - static_assert((is_constructible<_Tp, _A0, _A1>::value), "Can't construct object in make_shared" ); - typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; - typedef allocator<_CntrlBlk> _Alloc2; - typedef __allocator_destructor<_Alloc2> _D2; - _Alloc2 __alloc2; - unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); - ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1); - shared_ptr<_Tp> __r; - __r.__ptr_ = __hold2.get()->get(); - __r.__cntrl_ = __hold2.release(); - __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); - return __r; -} - -template -template -shared_ptr<_Tp> -shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2) -{ - static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't construct object in make_shared" ); - typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; - typedef allocator<_CntrlBlk> _Alloc2; - typedef __allocator_destructor<_Alloc2> _D2; - _Alloc2 __alloc2; - unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); - ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2); - shared_ptr<_Tp> __r; - __r.__ptr_ = __hold2.get()->get(); - __r.__cntrl_ = __hold2.release(); - __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); - return __r; -} - -template -template -shared_ptr<_Tp> -shared_ptr<_Tp>::allocate_shared(const _Alloc& __a) -{ - static_assert((is_constructible<_Tp>::value), "Can't construct object in allocate_shared" ); - typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; - typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; - typedef __allocator_destructor<_Alloc2> _D2; - _Alloc2 __alloc2(__a); - unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); - ::new(static_cast(_VSTD::addressof(*__hold2.get()))) - _CntrlBlk(__a); - shared_ptr<_Tp> __r; - __r.__ptr_ = __hold2.get()->get(); - __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); - __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); - return __r; -} - -template -template -shared_ptr<_Tp> -shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0) -{ - static_assert((is_constructible<_Tp, _A0>::value), "Can't construct object in allocate_shared" ); - typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; - typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; - typedef __allocator_destructor<_Alloc2> _D2; - _Alloc2 __alloc2(__a); - unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); - ::new(static_cast(_VSTD::addressof(*__hold2.get()))) - _CntrlBlk(__a, __a0); - shared_ptr<_Tp> __r; - __r.__ptr_ = __hold2.get()->get(); - __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); - __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); - return __r; -} - -template -template -shared_ptr<_Tp> -shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1) -{ - static_assert((is_constructible<_Tp, _A0, _A1>::value), "Can't construct object in allocate_shared" ); - typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; - typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; - typedef __allocator_destructor<_Alloc2> _D2; - _Alloc2 __alloc2(__a); - unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); - ::new(static_cast(_VSTD::addressof(*__hold2.get()))) - _CntrlBlk(__a, __a0, __a1); - shared_ptr<_Tp> __r; - __r.__ptr_ = __hold2.get()->get(); - __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); - __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); - return __r; -} - -template -template -shared_ptr<_Tp> -shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2) -{ - static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't construct object in allocate_shared" ); - typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; - typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; - typedef __allocator_destructor<_Alloc2> _D2; - _Alloc2 __alloc2(__a); - unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); - ::new(static_cast(_VSTD::addressof(*__hold2.get()))) - _CntrlBlk(__a, __a0, __a1, __a2); - shared_ptr<_Tp> __r; - __r.__ptr_ = __hold2.get()->get(); - __r.__cntrl_ = _VSTD::addressof(*__hold2.release()); - __r.__enable_weak_this(__r.__ptr_, __r.__ptr_); - return __r; -} - -#endif // _LIBCPP_HAS_NO_VARIADICS - template shared_ptr<_Tp>::~shared_ptr() { @@ -4706,7 +4433,17 @@ >::type make_shared(_Args&& ...__args) { - return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...); + static_assert(is_constructible<_Tp, _Args...>::value, "Can't construct object in make_shared"); + typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; + typedef allocator<_CntrlBlk> _A2; + typedef __allocator_destructor<_A2> _D2; + + _A2 __a2; + unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); + ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...); + + return shared_ptr<_Tp>::__create_with_cntrl_block(__hold2.get()->get(), + __hold2.release()); } template @@ -4718,73 +4455,152 @@ >::type allocate_shared(const _Alloc& __a, _Args&& ...__args) { - return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...); + static_assert(is_constructible<_Tp, _Args...>::value, "Can't construct object in allocate_shared"); + + typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; + typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; + typedef __allocator_destructor<_A2> _D2; + + _A2 __a2(__a); + unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); + ::new(static_cast(_VSTD::addressof(*__hold2.get()))) + _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...); + + return shared_ptr<_Tp>::__create_with_cntrl_block(__hold2.get()->get(), + _VSTD::addressof(*__hold2.release())); } #else // _LIBCPP_HAS_NO_VARIADICS template -inline _LIBCPP_INLINE_VISIBILITY shared_ptr<_Tp> make_shared() { - return shared_ptr<_Tp>::make_shared(); + static_assert((is_constructible<_Tp>::value), "Can't construct object in make_shared" ); + typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; + typedef allocator<_CntrlBlk> _Alloc2; + typedef __allocator_destructor<_Alloc2> _D2; + _Alloc2 __alloc2; + unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); + ::new(__hold2.get()) _CntrlBlk(__alloc2); + return shared_ptr<_Tp>::__create_with_cntrl_block(__hold2.get()->get(), + __hold2.release()); } -template -inline _LIBCPP_INLINE_VISIBILITY +template +template shared_ptr<_Tp> make_shared(_A0& __a0) { - return shared_ptr<_Tp>::make_shared(__a0); + static_assert((is_constructible<_Tp, _A0>::value), "Can't construct object in make_shared" ); + typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; + typedef allocator<_CntrlBlk> _Alloc2; + typedef __allocator_destructor<_Alloc2> _D2; + _Alloc2 __alloc2; + unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); + ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0); + return shared_ptr<_Tp>::__create_with_cntrl_block(__hold2.get()->get(), + __hold2.release()); } -template -inline _LIBCPP_INLINE_VISIBILITY +template +template shared_ptr<_Tp> make_shared(_A0& __a0, _A1& __a1) { - return shared_ptr<_Tp>::make_shared(__a0, __a1); + static_assert((is_constructible<_Tp, _A0, _A1>::value), "Can't construct object in make_shared" ); + typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; + typedef allocator<_CntrlBlk> _Alloc2; + typedef __allocator_destructor<_Alloc2> _D2; + _Alloc2 __alloc2; + unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); + ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1); + return shared_ptr<_Tp>::__create_with_cntrl_block(__hold2.get()->get(), + __hold2.release()); } -template -inline _LIBCPP_INLINE_VISIBILITY +template +template shared_ptr<_Tp> make_shared(_A0& __a0, _A1& __a1, _A2& __a2) { - return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2); + static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't construct object in make_shared" ); + typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; + typedef allocator<_CntrlBlk> _Alloc2; + typedef __allocator_destructor<_Alloc2> _D2; + _Alloc2 __alloc2; + unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); + ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2); + return shared_ptr<_Tp>::__create_with_cntrl_block(__hold2.get()->get(), + __hold2.release()); } -template -inline _LIBCPP_INLINE_VISIBILITY +template +template shared_ptr<_Tp> allocate_shared(const _Alloc& __a) { - return shared_ptr<_Tp>::allocate_shared(__a); + static_assert((is_constructible<_Tp>::value), "Can't construct object in allocate_shared" ); + typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; + typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; + typedef __allocator_destructor<_Alloc2> _D2; + _Alloc2 __alloc2(__a); + unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); + ::new(static_cast(_VSTD::addressof(*__hold2.get()))) + _CntrlBlk(__a); + return shared_ptr<_Tp>::__create_with_cntrl_block(__hold2.get()->get(), + _VSTD::addressof(*__hold2.release())); } -template -inline _LIBCPP_INLINE_VISIBILITY +template +template shared_ptr<_Tp> allocate_shared(const _Alloc& __a, _A0& __a0) { - return shared_ptr<_Tp>::allocate_shared(__a, __a0); + static_assert((is_constructible<_Tp, _A0>::value), "Can't construct object in allocate_shared" ); + typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; + typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; + typedef __allocator_destructor<_Alloc2> _D2; + _Alloc2 __alloc2(__a); + unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); + ::new(static_cast(_VSTD::addressof(*__hold2.get()))) + _CntrlBlk(__a, __a0); + return shared_ptr<_Tp>::__create_with_cntrl_block(__hold2.get()->get(), + _VSTD::addressof(*__hold2.release())); } -template -inline _LIBCPP_INLINE_VISIBILITY +template +template shared_ptr<_Tp> allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1) { - return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1); + static_assert((is_constructible<_Tp, _A0, _A1>::value), "Can't construct object in allocate_shared" ); + typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; + typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; + typedef __allocator_destructor<_Alloc2> _D2; + _Alloc2 __alloc2(__a); + unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); + ::new(static_cast(_VSTD::addressof(*__hold2.get()))) + _CntrlBlk(__a, __a0, __a1); + return shared_ptr<_Tp>::__create_with_cntrl_block(__hold2.get()->get(), + _VSTD::addressof(*__hold2.release())); } -template -inline _LIBCPP_INLINE_VISIBILITY +template +template shared_ptr<_Tp> allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2) { - return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2); + static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't construct object in allocate_shared" ); + typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; + typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; + typedef __allocator_destructor<_Alloc2> _D2; + _Alloc2 __alloc2(__a); + unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1)); + ::new(static_cast(_VSTD::addressof(*__hold2.get()))) + _CntrlBlk(__a, __a0, __a1, __a2); + return shared_ptr<_Tp>::__create_with_cntrl_block(__hold2.get()->get(), + _VSTD::addressof(*__hold2.release())); } #endif // _LIBCPP_HAS_NO_VARIADICS