Skip to content

Commit 10aed27

Browse files
authored
[libc++] Simplify the std::pair constructor overload set (#81448)
This depends on enabling extensions in the implementation.
1 parent fd3eaf7 commit 10aed27

File tree

1 file changed

+27
-69
lines changed
  • libcxx/include/__utility

1 file changed

+27
-69
lines changed

libcxx/include/__utility/pair.h

Lines changed: 27 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,13 @@ struct _LIBCPP_TEMPLATE_VIS pair
120120
#else
121121
struct _CheckArgs {
122122
template <int&...>
123-
static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_explicit_default() {
124-
return is_default_constructible<_T1>::value && is_default_constructible<_T2>::value &&
125-
!__enable_implicit_default<>();
123+
static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_implicit_default() {
124+
return __is_implicitly_default_constructible<_T1>::value && __is_implicitly_default_constructible<_T2>::value;
126125
}
127126

128127
template <int&...>
129-
static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_implicit_default() {
130-
return __is_implicitly_default_constructible<_T1>::value && __is_implicitly_default_constructible<_T2>::value;
128+
static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_default() {
129+
return is_default_constructible<_T1>::value && is_default_constructible<_T2>::value;
131130
}
132131

133132
template <class _U1, class _U2>
@@ -139,58 +138,25 @@ struct _LIBCPP_TEMPLATE_VIS pair
139138
static _LIBCPP_HIDE_FROM_ABI constexpr bool __is_implicit() {
140139
return is_convertible<_U1, first_type>::value && is_convertible<_U2, second_type>::value;
141140
}
142-
143-
template <class _U1, class _U2>
144-
static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_explicit() {
145-
return __is_pair_constructible<_U1, _U2>() && !__is_implicit<_U1, _U2>();
146-
}
147-
148-
template <class _U1, class _U2>
149-
static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_implicit() {
150-
return __is_pair_constructible<_U1, _U2>() && __is_implicit<_U1, _U2>();
151-
}
152141
};
153142

154143
template <bool _MaybeEnable>
155144
using _CheckArgsDep _LIBCPP_NODEBUG =
156145
typename conditional< _MaybeEnable, _CheckArgs, __check_tuple_constructor_fail>::type;
157146

158-
template <bool _Dummy = true, __enable_if_t<_CheckArgsDep<_Dummy>::__enable_explicit_default(), int> = 0>
159-
explicit _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR pair() _NOEXCEPT_(
160-
is_nothrow_default_constructible<first_type>::value&& is_nothrow_default_constructible<second_type>::value)
161-
: first(), second() {}
162-
163-
template <bool _Dummy = true, __enable_if_t<_CheckArgsDep<_Dummy>::__enable_implicit_default(), int> = 0>
164-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR pair() _NOEXCEPT_(
165-
is_nothrow_default_constructible<first_type>::value&& is_nothrow_default_constructible<second_type>::value)
147+
template <bool _Dummy = true, __enable_if_t<_CheckArgsDep<_Dummy>::__enable_default(), int> = 0>
148+
explicit(!_CheckArgsDep<_Dummy>::__enable_implicit_default()) _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR pair()
149+
_NOEXCEPT_(
150+
is_nothrow_default_constructible<first_type>::value&& is_nothrow_default_constructible<second_type>::value)
166151
: first(), second() {}
167152

168-
template <bool _Dummy = true,
169-
__enable_if_t<_CheckArgsDep<_Dummy>::template __enable_explicit<_T1 const&, _T2 const&>(), int> = 0>
170-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit pair(_T1 const& __t1, _T2 const& __t2)
153+
template <bool _Dummy = true,
154+
__enable_if_t<_CheckArgsDep<_Dummy>::template __is_pair_constructible<_T1 const&, _T2 const&>(), int> = 0>
155+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(
156+
!_CheckArgsDep<_Dummy>::template __is_implicit<_T1 const&, _T2 const&>()) pair(_T1 const& __t1, _T2 const& __t2)
171157
_NOEXCEPT_(is_nothrow_copy_constructible<first_type>::value&& is_nothrow_copy_constructible<second_type>::value)
172158
: first(__t1), second(__t2) {}
173159

174-
template <bool _Dummy = true,
175-
__enable_if_t<_CheckArgsDep<_Dummy>::template __enable_implicit<_T1 const&, _T2 const&>(), int> = 0>
176-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair(_T1 const& __t1, _T2 const& __t2)
177-
_NOEXCEPT_(is_nothrow_copy_constructible<first_type>::value&& is_nothrow_copy_constructible<second_type>::value)
178-
: first(__t1), second(__t2) {}
179-
180-
template <
181-
# if _LIBCPP_STD_VER >= 23 // http://wg21.link/P1951
182-
class _U1 = _T1,
183-
class _U2 = _T2,
184-
# else
185-
class _U1,
186-
class _U2,
187-
# endif
188-
__enable_if_t<_CheckArgs::template __enable_explicit<_U1, _U2>(), int> = 0 >
189-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit pair(_U1&& __u1, _U2&& __u2)
190-
_NOEXCEPT_(is_nothrow_constructible<first_type, _U1>::value&& is_nothrow_constructible<second_type, _U2>::value)
191-
: first(std::forward<_U1>(__u1)), second(std::forward<_U2>(__u2)) {
192-
}
193-
194160
template <
195161
# if _LIBCPP_STD_VER >= 23 // http://wg21.link/P1951
196162
class _U1 = _T1,
@@ -199,9 +165,11 @@ struct _LIBCPP_TEMPLATE_VIS pair
199165
class _U1,
200166
class _U2,
201167
# endif
202-
__enable_if_t<_CheckArgs::template __enable_implicit<_U1, _U2>(), int> = 0 >
203-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair(_U1&& __u1, _U2&& __u2)
204-
_NOEXCEPT_(is_nothrow_constructible<first_type, _U1>::value&& is_nothrow_constructible<second_type, _U2>::value)
168+
__enable_if_t<_CheckArgs::template __is_pair_constructible<_U1, _U2>(), int> = 0 >
169+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(!_CheckArgs::template __is_implicit<_U1, _U2>())
170+
pair(_U1&& __u1, _U2&& __u2)
171+
_NOEXCEPT_((is_nothrow_constructible<first_type, _U1>::value &&
172+
is_nothrow_constructible<second_type, _U2>::value))
205173
: first(std::forward<_U1>(__u1)), second(std::forward<_U2>(__u2)) {
206174
}
207175

@@ -215,28 +183,18 @@ struct _LIBCPP_TEMPLATE_VIS pair
215183

216184
template <class _U1,
217185
class _U2,
218-
__enable_if_t<_CheckArgs::template __enable_explicit<_U1 const&, _U2 const&>(), int> = 0>
219-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit pair(pair<_U1, _U2> const& __p)
220-
_NOEXCEPT_(is_nothrow_constructible<first_type, _U1 const&>::value&&
221-
is_nothrow_constructible<second_type, _U2 const&>::value)
222-
: first(__p.first), second(__p.second) {}
223-
224-
template <class _U1,
225-
class _U2,
226-
__enable_if_t<_CheckArgs::template __enable_implicit<_U1 const&, _U2 const&>(), int> = 0>
227-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair(pair<_U1, _U2> const& __p)
228-
_NOEXCEPT_(is_nothrow_constructible<first_type, _U1 const&>::value&&
229-
is_nothrow_constructible<second_type, _U2 const&>::value)
186+
__enable_if_t<_CheckArgs::template __is_pair_constructible<_U1 const&, _U2 const&>(), int> = 0>
187+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(
188+
!_CheckArgs::template __is_implicit<_U1 const&, _U2 const&>()) pair(pair<_U1, _U2> const& __p)
189+
_NOEXCEPT_((is_nothrow_constructible<first_type, _U1 const&>::value &&
190+
is_nothrow_constructible<second_type, _U2 const&>::value))
230191
: first(__p.first), second(__p.second) {}
231192

232-
template <class _U1, class _U2, __enable_if_t<_CheckArgs::template __enable_explicit<_U1, _U2>(), int> = 0>
233-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit pair(pair<_U1, _U2>&& __p) _NOEXCEPT_(
234-
is_nothrow_constructible<first_type, _U1&&>::value&& is_nothrow_constructible<second_type, _U2&&>::value)
235-
: first(std::forward<_U1>(__p.first)), second(std::forward<_U2>(__p.second)) {}
236-
237-
template <class _U1, class _U2, __enable_if_t<_CheckArgs::template __enable_implicit<_U1, _U2>(), int> = 0>
238-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair(pair<_U1, _U2>&& __p) _NOEXCEPT_(
239-
is_nothrow_constructible<first_type, _U1&&>::value&& is_nothrow_constructible<second_type, _U2&&>::value)
193+
template <class _U1, class _U2, __enable_if_t<_CheckArgs::template __is_pair_constructible<_U1, _U2>(), int> = 0>
194+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(!_CheckArgs::template __is_implicit<_U1, _U2>())
195+
pair(pair<_U1, _U2>&& __p)
196+
_NOEXCEPT_((is_nothrow_constructible<first_type, _U1&&>::value &&
197+
is_nothrow_constructible<second_type, _U2&&>::value))
240198
: first(std::forward<_U1>(__p.first)), second(std::forward<_U2>(__p.second)) {}
241199

242200
# if _LIBCPP_STD_VER >= 23

0 commit comments

Comments
 (0)