unstick r375504

Revision 375504

Date:
2019/10/22 15:16:49
Author:
zoecarver
Revision Log:
[libcxx] Remove shared_ptr::make_shared

Summary: 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.

Reviewers: EricWF, mclow.lists, ldionne

Subscribers: christof, dexonsmith, libcxx-commits

Tags: #libc

Differential Revision: https://reviews.llvm.org/D68805
Files:

Legend:

 
Added
 
Removed
 
Modified
  • libcxx/trunk/include/memory

     
    3871 3871 : nullptr);}
    3872 3872 #endif // _LIBCPP_NO_RTTI
    3873 3873
    3874 template<class ..._Args>
    3875 static
    3876 shared_ptr<_Tp>
    3877 make_shared(_Args&& ...__args);
    3874 template<class _Yp, class _CntrlBlk>
    3875 static shared_ptr<_Tp>
    3876 __create_with_control_block(_Yp* __p, _CntrlBlk* __cntrl)
    3877 {
    3878 shared_ptr<_Tp> __r;
    3879 __r.__ptr_ = __p;
    3880 __r.__cntrl_ = __cntrl;
    3881 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
    3882 return __r;
    3883 }
    3878 3884
    3879 3885 template<class _Alloc, class ..._Args>
    3880 3886 static
     
    4194 4200 }
    4195 4201
    4196 4202 template<class _Tp>
    4197 template<class ..._Args>
    4198 shared_ptr<_Tp>
    4199 shared_ptr<_Tp>::make_shared(_Args&& ...__args)
    4200 {
    4201 static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in make_shared" );
    4202 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
    4203 typedef allocator<_CntrlBlk> _A2;
    4204 typedef __allocator_destructor<_A2> _D2;
    4205 _A2 __a2;
    4206 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
    4207 ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
    4208 shared_ptr<_Tp> __r;
    4209 __r.__ptr_ = __hold2.get()->get();
    4210 __r.__cntrl_ = __hold2.release();
    4211 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
    4212 return __r;
    4213 }
    4214
    4215 template<class _Tp>
    4216 4203 template<class _Alloc, class ..._Args>
    4217 4204 shared_ptr<_Tp>
    4218 4205 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args)
     
    4422 4409 >::type
    4423 4410 make_shared(_Args&& ...__args)
    4424 4411 {
    4425 return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
    4412 static_assert(is_constructible<_Tp, _Args...>::value, "Can't construct object in make_shared");
    4413 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
    4414 typedef allocator<_CntrlBlk> _A2;
    4415 typedef __allocator_destructor<_A2> _D2;
    4416
    4417 _A2 __a2;
    4418 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
    4419 ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
    4420
    4421 _Tp *__ptr = __hold2.get()->get();
    4422 return shared_ptr<_Tp>::__create_with_control_block(__ptr, __hold2.release());
    4426 4423 }
    4427 4424
    4428 4425 template<class _Tp, class _Alloc, class ..._Args>