@@ -141,6 +141,31 @@ struct _LIBCPP_TEMPLATE_VIS pair
141
141
_NOEXCEPT_(is_nothrow_copy_constructible<first_type>::value&& is_nothrow_copy_constructible<second_type>::value)
142
142
: first(__t1), second(__t2) {}
143
143
144
+ // Make pair trivially copyable if we have a way to do it
145
+ static const bool __enable_defaulted_assignment_operators =
146
+ !is_reference<first_type>::value && !is_reference<second_type>::value;
147
+ # if _LIBCPP_STD_VER >= 20
148
+ static const bool __has_defaulted_members = __enable_defaulted_assignment_operators;
149
+
150
+ _LIBCPP_HIDE_FROM_ABI constexpr pair& operator =(const pair&)
151
+ requires __enable_defaulted_assignment_operators
152
+ = default ;
153
+
154
+ _LIBCPP_HIDE_FROM_ABI constexpr pair& operator =(pair&&)
155
+ requires __enable_defaulted_assignment_operators
156
+ = default ;
157
+ # elif __has_attribute(__enable_if__)
158
+ static const bool __has_defaulted_members = __enable_defaulted_assignment_operators;
159
+
160
+ _LIBCPP_HIDE_FROM_ABI pair& operator =(const pair&)
161
+ __attribute__ ((__enable_if__(__enable_defaulted_assignment_operators, " " ))) = default;
162
+
163
+ _LIBCPP_HIDE_FROM_ABI pair& operator =(pair&&)
164
+ __attribute__ ((__enable_if__(__enable_defaulted_assignment_operators, " " ))) = default;
165
+ # else
166
+ static const bool __has_defaulted_members = false ;
167
+ # endif // __has_attribute(__enable_if__)
168
+
144
169
template <
145
170
# if _LIBCPP_STD_VER >= 23 // http://wg21.link/P1951
146
171
class _U1 = _T1,
@@ -221,18 +246,21 @@ struct _LIBCPP_TEMPLATE_VIS pair
221
246
typename __make_tuple_indices<sizeof...(_Args2) >::type()) {}
222
247
223
248
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair&
224
- operator =(__conditional_t < is_copy_assignable<first_type>::value && is_copy_assignable<second_type>::value,
225
- pair,
226
- __nat> const & __p)
249
+ operator =(__conditional_t <
250
+ !__has_defaulted_members && is_copy_assignable<first_type>::value && is_copy_assignable<second_type>::value,
251
+ pair,
252
+ __nat> const & __p)
227
253
_NOEXCEPT_ (is_nothrow_copy_assignable<first_type>::value&& is_nothrow_copy_assignable<second_type>::value) {
228
254
first = __p.first ;
229
255
second = __p.second ;
230
256
return *this ;
231
257
}
232
258
233
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair& operator =(
234
- __conditional_t < is_move_assignable<first_type>::value && is_move_assignable<second_type>::value, pair, __nat>&&
235
- __p)
259
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair&
260
+ operator =(__conditional_t <
261
+ !__has_defaulted_members && is_move_assignable<first_type>::value && is_move_assignable<second_type>::value,
262
+ pair,
263
+ __nat>&& __p)
236
264
_NOEXCEPT_ (is_nothrow_move_assignable<first_type>::value&& is_nothrow_move_assignable<second_type>::value) {
237
265
first = std::forward<first_type>(__p.first );
238
266
second = std::forward<second_type>(__p.second );
0 commit comments