[libcxx-commits] [PATCH] D68805: [libcxx] Remove shared_ptr::make_shared
Zoe Carver via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Oct 10 08:59:20 PDT 2019
zoecarver created this revision.
zoecarver added reviewers: EricWF, mclow.lists, ldionne.
Herald added subscribers: libcxx-commits, dexonsmith, christof.
Herald added a project: libc++.
This patch removes `shared_ptr::make_shared` as it is not part of the standard. This patch also adds __create_with_cntrl_block, which is a help function that can be used in std::allocate_shared and std::make_shared. This is the third patch (out of 4) from D66178 <https://reviews.llvm.org/D66178>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D68805
Files:
libcxx/include/memory
Index: libcxx/include/memory
===================================================================
--- libcxx/include/memory
+++ libcxx/include/memory
@@ -3871,10 +3871,16 @@
: nullptr);}
#endif // _LIBCPP_NO_RTTI
- template<class ..._Args>
- static
- shared_ptr<_Tp>
- make_shared(_Args&& ...__args);
+ template<class _Yp, class _CntrlBlk>
+ 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;
+ }
template<class _Alloc, class ..._Args>
static
@@ -4193,25 +4199,6 @@
__r.release();
}
-template<class _Tp>
-template<class ..._Args>
-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<class _Tp>
template<class _Alloc, class ..._Args>
shared_ptr<_Tp>
@@ -4422,7 +4409,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<class _Tp, class _Alloc, class ..._Args>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68805.224375.patch
Type: text/x-patch
Size: 2341 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20191010/7ac30ac5/attachment-0001.bin>
More information about the libcxx-commits
mailing list