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