Skip to content

Commit 9489d8b

Browse files
committed
use Tim's approach
1 parent 73923e3 commit 9489d8b

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

libcxx/include/__memory/shared_ptr.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ struct __shared_ptr_deleter_ctor_reqs {
403403
__well_formed_deleter<_Dp, _Yp*>::value;
404404
};
405405

406-
template <class _Dp, class _Tp>
406+
template <class _Dp>
407407
using __shared_ptr_nullptr_deleter_ctor_reqs = _And<is_move_constructible<_Dp>, __well_formed_deleter<_Dp, nullptr_t> >;
408408

409409
#if defined(_LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI)
@@ -414,6 +414,8 @@ using __shared_ptr_nullptr_deleter_ctor_reqs = _And<is_move_constructible<_Dp>,
414414

415415
template <class _Tp>
416416
class _LIBCPP_SHARED_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS shared_ptr {
417+
struct __nullptr_sfinae_tag {};
418+
417419
public:
418420
#if _LIBCPP_STD_VER >= 17
419421
typedef weak_ptr<_Tp> weak_type;
@@ -505,8 +507,12 @@ class _LIBCPP_SHARED_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS shared_ptr {
505507
#endif // _LIBCPP_HAS_NO_EXCEPTIONS
506508
}
507509

508-
template <class _Dp, __enable_if_t<__shared_ptr_nullptr_deleter_ctor_reqs<_Dp, _Tp>::value, int> = 0 >
509-
_LIBCPP_HIDE_FROM_ABI shared_ptr(nullptr_t __p, _Dp __d) : __ptr_(nullptr) {
510+
template <class _Dp>
511+
_LIBCPP_HIDE_FROM_ABI shared_ptr(
512+
nullptr_t __p,
513+
_Dp __d,
514+
__enable_if_t<__shared_ptr_nullptr_deleter_ctor_reqs<_Dp>::value, __nullptr_sfinae_tag> = __nullptr_sfinae_tag())
515+
: __ptr_(nullptr) {
510516
#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
511517
try {
512518
#endif // _LIBCPP_HAS_NO_EXCEPTIONS
@@ -525,8 +531,13 @@ class _LIBCPP_SHARED_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS shared_ptr {
525531
#endif // _LIBCPP_HAS_NO_EXCEPTIONS
526532
}
527533

528-
template <class _Dp, class _Alloc, __enable_if_t<__shared_ptr_nullptr_deleter_ctor_reqs<_Dp, _Tp>::value, int> = 0 >
529-
_LIBCPP_HIDE_FROM_ABI shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a) : __ptr_(nullptr) {
534+
template <class _Dp, class _Alloc>
535+
_LIBCPP_HIDE_FROM_ABI shared_ptr(
536+
nullptr_t __p,
537+
_Dp __d,
538+
_Alloc __a,
539+
__enable_if_t<__shared_ptr_nullptr_deleter_ctor_reqs<_Dp>::value, __nullptr_sfinae_tag> = __nullptr_sfinae_tag())
540+
: __ptr_(nullptr) {
530541
#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
531542
try {
532543
#endif // _LIBCPP_HAS_NO_EXCEPTIONS

0 commit comments

Comments
 (0)