Skip to content

Commit 4da76ea

Browse files
committed
[libc++][NFC] Refactor enable_ifs in defaulted arguments to defaulted template arguments
This brings most of the enable_ifs in libc++ to the same style. It also has the nice side-effect of reducing the size of names of these symbols, since the arguments don't get mangled anymore. Reviewed By: #libc, Mordante Spies: Mordante, libcxx-commits Differential Revision: https://reviews.llvm.org/D157748
1 parent fc06cce commit 4da76ea

15 files changed

+110
-161
lines changed

libcxx/include/__chrono/duration.h

+9-17
Original file line numberDiff line numberDiff line change
@@ -234,28 +234,20 @@ class _LIBCPP_TEMPLATE_VIS duration
234234
_LIBCPP_HIDE_FROM_ABI duration() {}
235235
#endif
236236

237-
template <class _Rep2>
237+
template <class _Rep2, __enable_if_t<is_convertible<const _Rep2&, rep>::value &&
238+
(treat_as_floating_point<rep>::value ||
239+
!treat_as_floating_point<_Rep2>::value), int> = 0>
238240
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
239-
explicit duration(const _Rep2& __r,
240-
typename enable_if
241-
<
242-
is_convertible<const _Rep2&, rep>::value &&
243-
(treat_as_floating_point<rep>::value ||
244-
!treat_as_floating_point<_Rep2>::value)
245-
>::type* = nullptr)
241+
explicit duration(const _Rep2& __r)
246242
: __rep_(__r) {}
247243

248244
// conversions
249-
template <class _Rep2, class _Period2>
245+
template <class _Rep2, class _Period2, __enable_if_t<__no_overflow<_Period2, period>::value && (
246+
treat_as_floating_point<rep>::value ||
247+
(__no_overflow<_Period2, period>::type::den == 1 &&
248+
!treat_as_floating_point<_Rep2>::value)), int> = 0>
250249
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
251-
duration(const duration<_Rep2, _Period2>& __d,
252-
typename enable_if
253-
<
254-
__no_overflow<_Period2, period>::value && (
255-
treat_as_floating_point<rep>::value ||
256-
(__no_overflow<_Period2, period>::type::den == 1 &&
257-
!treat_as_floating_point<_Rep2>::value))
258-
>::type* = nullptr)
250+
duration(const duration<_Rep2, _Period2>& __d)
259251
: __rep_(chrono::duration_cast<duration>(__d).count()) {}
260252

261253
// observer

libcxx/include/__chrono/time_point.h

+2-6
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,9 @@ class _LIBCPP_TEMPLATE_VIS time_point
4949
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit time_point(const duration& __d) : __d_(__d) {}
5050

5151
// conversions
52-
template <class _Duration2>
52+
template <class _Duration2, __enable_if_t<is_convertible<_Duration2, duration>::value, int> = 0>
5353
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
54-
time_point(const time_point<clock, _Duration2>& __t,
55-
typename enable_if
56-
<
57-
is_convertible<_Duration2, duration>::value
58-
>::type* = nullptr)
54+
time_point(const time_point<clock, _Duration2>& __t)
5955
: __d_(__t.time_since_epoch()) {}
6056

6157
// observer

libcxx/include/__iterator/wrap_iter.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ class __wrap_iter
4545
: __i_()
4646
{
4747
}
48-
template <class _Up> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
49-
__wrap_iter(const __wrap_iter<_Up>& __u,
50-
typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = nullptr) _NOEXCEPT
48+
template <class _Up, __enable_if_t<is_convertible<_Up, iterator_type>::value, int> = 0>
49+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter(const __wrap_iter<_Up>& __u) _NOEXCEPT
5150
: __i_(__u.base())
5251
{
5352
}

libcxx/include/__memory/shared_ptr.h

+17-18
Original file line numberDiff line numberDiff line change
@@ -1624,20 +1624,22 @@ class _LIBCPP_SHARED_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS weak_ptr
16241624
public:
16251625
_LIBCPP_INLINE_VISIBILITY
16261626
_LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT;
1627-
template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(shared_ptr<_Yp> const& __r,
1628-
typename enable_if<__compatible_with<_Yp, _Tp>::value, __nat*>::type = 0)
1629-
_NOEXCEPT;
1627+
1628+
template<class _Yp, __enable_if_t<__compatible_with<_Yp, _Tp>::value, int> = 0>
1629+
_LIBCPP_INLINE_VISIBILITY weak_ptr(shared_ptr<_Yp> const& __r) _NOEXCEPT;
1630+
16301631
_LIBCPP_INLINE_VISIBILITY
16311632
weak_ptr(weak_ptr const& __r) _NOEXCEPT;
1632-
template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp> const& __r,
1633-
typename enable_if<__compatible_with<_Yp, _Tp>::value, __nat*>::type = 0)
1634-
_NOEXCEPT;
1633+
1634+
template<class _Yp, __enable_if_t<__compatible_with<_Yp, _Tp>::value, int> = 0>
1635+
_LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp> const& __r) _NOEXCEPT;
16351636

16361637
_LIBCPP_INLINE_VISIBILITY
16371638
weak_ptr(weak_ptr&& __r) _NOEXCEPT;
1638-
template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp>&& __r,
1639-
typename enable_if<__compatible_with<_Yp, _Tp>::value, __nat*>::type = 0)
1640-
_NOEXCEPT;
1639+
1640+
template<class _Yp, __enable_if_t<__compatible_with<_Yp, _Tp>::value, int> = 0>
1641+
_LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp>&& __r) _NOEXCEPT;
1642+
16411643
_LIBCPP_HIDE_FROM_ABI ~weak_ptr();
16421644

16431645
_LIBCPP_INLINE_VISIBILITY
@@ -1706,10 +1708,9 @@ weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT
17061708
}
17071709

17081710
template<class _Tp>
1709-
template<class _Yp>
1711+
template<class _Yp, __enable_if_t<__compatible_with<_Yp, _Tp>::value, int> >
17101712
inline
1711-
weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
1712-
typename enable_if<__compatible_with<_Yp, _Tp>::value, __nat*>::type)
1713+
weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r)
17131714
_NOEXCEPT
17141715
: __ptr_(__r.__ptr_),
17151716
__cntrl_(__r.__cntrl_)
@@ -1719,10 +1720,9 @@ weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
17191720
}
17201721

17211722
template<class _Tp>
1722-
template<class _Yp>
1723+
template<class _Yp, __enable_if_t<__compatible_with<_Yp, _Tp>::value, int> >
17231724
inline
1724-
weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
1725-
typename enable_if<__compatible_with<_Yp, _Tp>::value, __nat*>::type)
1725+
weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r)
17261726
_NOEXCEPT
17271727
: __ptr_(__r.__ptr_),
17281728
__cntrl_(__r.__cntrl_)
@@ -1742,10 +1742,9 @@ weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT
17421742
}
17431743

17441744
template<class _Tp>
1745-
template<class _Yp>
1745+
template<class _Yp, __enable_if_t<__compatible_with<_Yp, _Tp>::value, int> >
17461746
inline
1747-
weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
1748-
typename enable_if<__compatible_with<_Yp, _Tp>::value, __nat*>::type)
1747+
weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r)
17491748
_NOEXCEPT
17501749
: __ptr_(__r.__ptr_),
17511750
__cntrl_(__r.__cntrl_)

libcxx/include/__memory/unique_ptr.h

+5-7
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ struct _LIBCPP_TEMPLATE_VIS default_delete {
5858
#else
5959
_LIBCPP_INLINE_VISIBILITY default_delete() {}
6060
#endif
61-
template <class _Up>
61+
template <class _Up, __enable_if_t<is_convertible<_Up*, _Tp*>::value, int> = 0>
6262
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 default_delete(
63-
const default_delete<_Up>&, typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
63+
const default_delete<_Up>&) _NOEXCEPT {}
6464

6565
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator()(_Tp* __ptr) const _NOEXCEPT {
6666
static_assert(sizeof(_Tp) >= 0, "cannot delete an incomplete type");
@@ -221,12 +221,10 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr {
221221
: __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {}
222222

223223
#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
224-
template <class _Up>
224+
template <class _Up, __enable_if_t<is_convertible<_Up*, _Tp*>::value &&
225+
is_same<_Dp, default_delete<_Tp> >::value, int> = 0>
225226
_LIBCPP_INLINE_VISIBILITY
226-
unique_ptr(auto_ptr<_Up>&& __p,
227-
typename enable_if<is_convertible<_Up*, _Tp*>::value &&
228-
is_same<_Dp, default_delete<_Tp> >::value,
229-
__nat>::type = __nat()) _NOEXCEPT
227+
unique_ptr(auto_ptr<_Up>&& __p) _NOEXCEPT
230228
: __ptr_(__p.release(), __value_init_tag()) {}
231229
#endif
232230

libcxx/include/__random/discard_block_engine.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,10 @@ class _LIBCPP_TEMPLATE_VIS discard_block_engine
7272
#endif // _LIBCPP_CXX03_LANG
7373
_LIBCPP_INLINE_VISIBILITY
7474
explicit discard_block_engine(result_type __sd) : __e_(__sd), __n_(0) {}
75-
template<class _Sseq>
75+
template<class _Sseq, __enable_if_t<__is_seed_sequence<_Sseq, discard_block_engine>::value &&
76+
!is_convertible<_Sseq, _Engine>::value, int> = 0>
7677
_LIBCPP_INLINE_VISIBILITY
77-
explicit discard_block_engine(_Sseq& __q,
78-
typename enable_if<__is_seed_sequence<_Sseq, discard_block_engine>::value &&
79-
!is_convertible<_Sseq, _Engine>::value>::type* = 0)
78+
explicit discard_block_engine(_Sseq& __q)
8079
: __e_(__q), __n_(0) {}
8180
_LIBCPP_INLINE_VISIBILITY
8281
void seed() {__e_.seed(); __n_ = 0;}

libcxx/include/__random/independent_bits_engine.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,10 @@ class _LIBCPP_TEMPLATE_VIS independent_bits_engine
104104
#endif // _LIBCPP_CXX03_LANG
105105
_LIBCPP_INLINE_VISIBILITY
106106
explicit independent_bits_engine(result_type __sd) : __e_(__sd) {}
107-
template<class _Sseq>
107+
template<class _Sseq, __enable_if_t<__is_seed_sequence<_Sseq, independent_bits_engine>::value &&
108+
!is_convertible<_Sseq, _Engine>::value, int> = 0>
108109
_LIBCPP_INLINE_VISIBILITY
109-
explicit independent_bits_engine(_Sseq& __q,
110-
typename enable_if<__is_seed_sequence<_Sseq, independent_bits_engine>::value &&
111-
!is_convertible<_Sseq, _Engine>::value>::type* = 0)
110+
explicit independent_bits_engine(_Sseq& __q)
112111
: __e_(__q) {}
113112
_LIBCPP_INLINE_VISIBILITY
114113
void seed() {__e_.seed();}

libcxx/include/__random/linear_congruential_engine.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,9 @@ class _LIBCPP_TEMPLATE_VIS linear_congruential_engine
246246
seed(__s);
247247
}
248248
#endif
249-
template<class _Sseq>
249+
template<class _Sseq, __enable_if_t<__is_seed_sequence<_Sseq, linear_congruential_engine>::value, int> = 0>
250250
_LIBCPP_INLINE_VISIBILITY
251-
explicit linear_congruential_engine(_Sseq& __q,
252-
typename enable_if<__is_seed_sequence<_Sseq, linear_congruential_engine>::value>::type* = 0)
251+
explicit linear_congruential_engine(_Sseq& __q)
253252
{seed(__q);}
254253
_LIBCPP_INLINE_VISIBILITY
255254
void seed(result_type __s = default_seed)

libcxx/include/__random/mersenne_twister_engine.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,9 @@ class _LIBCPP_TEMPLATE_VIS mersenne_twister_engine
135135
seed(__sd);
136136
}
137137
#endif
138-
template<class _Sseq>
138+
template<class _Sseq, __enable_if_t<__is_seed_sequence<_Sseq, mersenne_twister_engine>::value, int> = 0>
139139
_LIBCPP_INLINE_VISIBILITY
140-
explicit mersenne_twister_engine(_Sseq& __q,
141-
typename enable_if<__is_seed_sequence<_Sseq, mersenne_twister_engine>::value>::type* = 0)
140+
explicit mersenne_twister_engine(_Sseq& __q)
142141
{seed(__q);}
143142
_LIBCPP_HIDE_FROM_ABI void seed(result_type __sd = default_seed);
144143
template<class _Sseq, __enable_if_t<__is_seed_sequence<_Sseq, mersenne_twister_engine>::value, int> = 0>

libcxx/include/__random/shuffle_order_engine.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,10 @@ class _LIBCPP_TEMPLATE_VIS shuffle_order_engine
9898
#endif // _LIBCPP_CXX03_LANG
9999
_LIBCPP_INLINE_VISIBILITY
100100
explicit shuffle_order_engine(result_type __sd) : __e_(__sd) {__init();}
101-
template<class _Sseq>
101+
template<class _Sseq, __enable_if_t<__is_seed_sequence<_Sseq, shuffle_order_engine>::value &&
102+
!is_convertible<_Sseq, _Engine>::value, int> = 0>
102103
_LIBCPP_INLINE_VISIBILITY
103-
explicit shuffle_order_engine(_Sseq& __q,
104-
typename enable_if<__is_seed_sequence<_Sseq, shuffle_order_engine>::value &&
105-
!is_convertible<_Sseq, _Engine>::value>::type* = 0)
104+
explicit shuffle_order_engine(_Sseq& __q)
106105
: __e_(__q) {__init();}
107106
_LIBCPP_INLINE_VISIBILITY
108107
void seed() {__e_.seed(); __init();}

libcxx/include/__random/subtract_with_carry_engine.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,9 @@ class _LIBCPP_TEMPLATE_VIS subtract_with_carry_engine
101101
seed(__sd);
102102
}
103103
#endif
104-
template<class _Sseq>
104+
template<class _Sseq, __enable_if_t<__is_seed_sequence<_Sseq, subtract_with_carry_engine>::value, int> = 0>
105105
_LIBCPP_INLINE_VISIBILITY
106-
explicit subtract_with_carry_engine(_Sseq& __q,
107-
typename enable_if<__is_seed_sequence<_Sseq, subtract_with_carry_engine>::value>::type* = 0)
106+
explicit subtract_with_carry_engine(_Sseq& __q)
108107
{seed(__q);}
109108
_LIBCPP_INLINE_VISIBILITY
110109
void seed(result_type __sd = default_seed)

libcxx/include/__system_error/error_code.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ class _LIBCPP_EXPORTED_FROM_ABI error_code {
4949

5050
_LIBCPP_HIDE_FROM_ABI error_code(int __val, const error_category& __cat) _NOEXCEPT : __val_(__val), __cat_(&__cat) {}
5151

52-
template <class _Ep>
53-
_LIBCPP_HIDE_FROM_ABI
54-
error_code(_Ep __e, typename enable_if<is_error_code_enum<_Ep>::value>::type* = nullptr) _NOEXCEPT {
52+
template <class _Ep, __enable_if_t<is_error_code_enum<_Ep>::value, int> = 0>
53+
_LIBCPP_HIDE_FROM_ABI error_code(_Ep __e) _NOEXCEPT {
5554
using __adl_only::make_error_code;
5655
*this = make_error_code(__e);
5756
}

libcxx/include/__system_error/error_condition.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ class _LIBCPP_EXPORTED_FROM_ABI error_condition {
5858
: __val_(__val),
5959
__cat_(&__cat) {}
6060

61-
template <class _Ep>
62-
_LIBCPP_HIDE_FROM_ABI
63-
error_condition(_Ep __e, typename enable_if<is_error_condition_enum<_Ep>::value>::type* = nullptr) _NOEXCEPT {
61+
template <class _Ep, __enable_if_t<is_error_condition_enum<_Ep>::value, int> = 0>
62+
_LIBCPP_HIDE_FROM_ABI error_condition(_Ep __e) _NOEXCEPT {
6463
using __adl_only::make_error_condition;
6564
*this = make_error_condition(__e);
6665
}

0 commit comments

Comments
 (0)