Skip to content

Commit 8f9cc3b

Browse files
committed
[libc++][NFC] Use std::enable_if instead of _EnableB helper in pair
This doesn't impact the compile-time efficiency, but we get better diagnostics when an overload is disabled.
1 parent badcd58 commit 8f9cc3b

File tree

1 file changed

+26
-29
lines changed
  • libcxx/include/__utility

1 file changed

+26
-29
lines changed

libcxx/include/__utility/pair.h

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ struct _LIBCPP_TEMPLATE_VIS pair
7272
return *this;
7373
}
7474
#else
75-
template <bool _Val>
76-
using _EnableB _LIBCPP_NODEBUG_TYPE = typename enable_if<_Val, bool>::type;
77-
7875
struct _CheckArgs {
7976
template <int&...>
8077
static constexpr bool __enable_explicit_default() {
@@ -136,105 +133,105 @@ struct _LIBCPP_TEMPLATE_VIS pair
136133
__check_tuple_constructor_fail
137134
>::type;
138135

139-
template<bool _Dummy = true, _EnableB<
136+
template<bool _Dummy = true, typename enable_if<
140137
_CheckArgsDep<_Dummy>::__enable_explicit_default()
141-
> = false>
138+
>::type* = nullptr>
142139
explicit _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
143140
pair() _NOEXCEPT_(is_nothrow_default_constructible<first_type>::value &&
144141
is_nothrow_default_constructible<second_type>::value)
145142
: first(), second() {}
146143

147-
template<bool _Dummy = true, _EnableB<
144+
template<bool _Dummy = true, typename enable_if<
148145
_CheckArgsDep<_Dummy>::__enable_implicit_default()
149-
> = false>
146+
>::type* = nullptr>
150147
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
151148
pair() _NOEXCEPT_(is_nothrow_default_constructible<first_type>::value &&
152149
is_nothrow_default_constructible<second_type>::value)
153150
: first(), second() {}
154151

155-
template <bool _Dummy = true, _EnableB<
152+
template <bool _Dummy = true, typename enable_if<
156153
_CheckArgsDep<_Dummy>::template __enable_explicit<_T1 const&, _T2 const&>()
157-
> = false>
154+
>::type* = nullptr>
158155
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
159156
explicit pair(_T1 const& __t1, _T2 const& __t2)
160157
_NOEXCEPT_(is_nothrow_copy_constructible<first_type>::value &&
161158
is_nothrow_copy_constructible<second_type>::value)
162159
: first(__t1), second(__t2) {}
163160

164-
template<bool _Dummy = true, _EnableB<
161+
template<bool _Dummy = true, typename enable_if<
165162
_CheckArgsDep<_Dummy>::template __enable_implicit<_T1 const&, _T2 const&>()
166-
> = false>
163+
>::type* = nullptr>
167164
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
168165
pair(_T1 const& __t1, _T2 const& __t2)
169166
_NOEXCEPT_(is_nothrow_copy_constructible<first_type>::value &&
170167
is_nothrow_copy_constructible<second_type>::value)
171168
: first(__t1), second(__t2) {}
172169

173-
template<class _U1, class _U2, _EnableB<
170+
template<class _U1, class _U2, typename enable_if<
174171
_CheckArgs::template __enable_explicit<_U1, _U2>()
175-
> = false>
172+
>::type* = nullptr>
176173
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
177174
explicit pair(_U1&& __u1, _U2&& __u2)
178175
_NOEXCEPT_((is_nothrow_constructible<first_type, _U1>::value &&
179176
is_nothrow_constructible<second_type, _U2>::value))
180177
: first(_VSTD::forward<_U1>(__u1)), second(_VSTD::forward<_U2>(__u2)) {}
181178

182-
template<class _U1, class _U2, _EnableB<
179+
template<class _U1, class _U2, typename enable_if<
183180
_CheckArgs::template __enable_implicit<_U1, _U2>()
184-
> = false>
181+
>::type* = nullptr>
185182
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
186183
pair(_U1&& __u1, _U2&& __u2)
187184
_NOEXCEPT_((is_nothrow_constructible<first_type, _U1>::value &&
188185
is_nothrow_constructible<second_type, _U2>::value))
189186
: first(_VSTD::forward<_U1>(__u1)), second(_VSTD::forward<_U2>(__u2)) {}
190187

191-
template<class _U1, class _U2, _EnableB<
188+
template<class _U1, class _U2, typename enable_if<
192189
_CheckArgs::template __enable_explicit<_U1 const&, _U2 const&>()
193-
> = false>
190+
>::type* = nullptr>
194191
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
195192
explicit pair(pair<_U1, _U2> const& __p)
196193
_NOEXCEPT_((is_nothrow_constructible<first_type, _U1 const&>::value &&
197194
is_nothrow_constructible<second_type, _U2 const&>::value))
198195
: first(__p.first), second(__p.second) {}
199196

200-
template<class _U1, class _U2, _EnableB<
197+
template<class _U1, class _U2, typename enable_if<
201198
_CheckArgs::template __enable_implicit<_U1 const&, _U2 const&>()
202-
> = false>
199+
>::type* = nullptr>
203200
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
204201
pair(pair<_U1, _U2> const& __p)
205202
_NOEXCEPT_((is_nothrow_constructible<first_type, _U1 const&>::value &&
206203
is_nothrow_constructible<second_type, _U2 const&>::value))
207204
: first(__p.first), second(__p.second) {}
208205

209-
template<class _U1, class _U2, _EnableB<
206+
template<class _U1, class _U2, typename enable_if<
210207
_CheckArgs::template __enable_explicit<_U1, _U2>()
211-
> = false>
208+
>::type* = nullptr>
212209
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
213210
explicit pair(pair<_U1, _U2>&&__p)
214211
_NOEXCEPT_((is_nothrow_constructible<first_type, _U1&&>::value &&
215212
is_nothrow_constructible<second_type, _U2&&>::value))
216213
: first(_VSTD::forward<_U1>(__p.first)), second(_VSTD::forward<_U2>(__p.second)) {}
217214

218-
template<class _U1, class _U2, _EnableB<
215+
template<class _U1, class _U2, typename enable_if<
219216
_CheckArgs::template __enable_implicit<_U1, _U2>()
220-
> = false>
217+
>::type* = nullptr>
221218
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
222219
pair(pair<_U1, _U2>&& __p)
223220
_NOEXCEPT_((is_nothrow_constructible<first_type, _U1&&>::value &&
224221
is_nothrow_constructible<second_type, _U2&&>::value))
225222
: first(_VSTD::forward<_U1>(__p.first)), second(_VSTD::forward<_U2>(__p.second)) {}
226223

227-
template<class _Tuple, _EnableB<
224+
template<class _Tuple, typename enable_if<
228225
_CheckTLC<_Tuple>::template __enable_explicit<_Tuple>()
229-
> = false>
226+
>::type* = nullptr>
230227
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
231228
explicit pair(_Tuple&& __p)
232229
: first(_VSTD::get<0>(_VSTD::forward<_Tuple>(__p))),
233230
second(_VSTD::get<1>(_VSTD::forward<_Tuple>(__p))) {}
234231

235-
template<class _Tuple, _EnableB<
232+
template<class _Tuple, typename enable_if<
236233
_CheckTLC<_Tuple>::template __enable_implicit<_Tuple>()
237-
> = false>
234+
>::type* = nullptr>
238235
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
239236
pair(_Tuple&& __p)
240237
: first(_VSTD::get<0>(_VSTD::forward<_Tuple>(__p))),
@@ -276,9 +273,9 @@ struct _LIBCPP_TEMPLATE_VIS pair
276273
return *this;
277274
}
278275

279-
template <class _Tuple, _EnableB<
276+
template <class _Tuple, typename enable_if<
280277
_CheckTLC<_Tuple>::template __enable_assign<_Tuple>()
281-
> = false>
278+
>::type* = nullptr>
282279
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
283280
pair& operator=(_Tuple&& __p) {
284281
first = _VSTD::get<0>(_VSTD::forward<_Tuple>(__p));

0 commit comments

Comments
 (0)