Skip to content

Commit ecbc1ef

Browse files
Use requires-clauses for pair and tuple since C++20 (#4819)
1 parent 0586819 commit ecbc1ef

File tree

3 files changed

+38
-53
lines changed

3 files changed

+38
-53
lines changed

stl/inc/expected

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,7 @@ public:
8787
}
8888

8989
friend constexpr void swap(unexpected& _Left, unexpected& _Right) noexcept(is_nothrow_swappable_v<_Err>)
90-
#if defined(__clang__) || defined(__EDG__) // TRANSITION, /permissive
91-
requires is_swappable_v<_Err>
92-
#else // ^^^ no workaround / workaround vvv
93-
requires is_swappable<_Err>::value
94-
#endif // ^^^ workaround ^^^
90+
requires is_swappable<_Err>::value // TRANSITION, /permissive needs ::value
9591
{
9692
_Left.swap(_Right);
9793
}
@@ -612,11 +608,7 @@ public:
612608
friend constexpr void swap(expected& _Lhs, expected& _Rhs) noexcept(
613609
is_nothrow_move_constructible_v<_Ty> && is_nothrow_swappable_v<_Ty> && is_nothrow_move_constructible_v<_Err>
614610
&& is_nothrow_swappable_v<_Err>)
615-
#if defined(__clang__) || defined(__EDG__) // TRANSITION, /permissive
616-
requires is_swappable_v<_Ty> && is_swappable_v<_Err>
617-
#else // ^^^ no workaround / workaround vvv
618-
requires is_swappable<_Ty>::value && is_swappable<_Err>::value
619-
#endif // ^^^ workaround ^^^
611+
requires is_swappable<_Ty>::value && is_swappable<_Err>::value // TRANSITION, /permissive needs ::value
620612
&& is_move_constructible_v<_Ty> && is_move_constructible_v<_Err>
621613
&& (is_nothrow_move_constructible_v<_Ty> || is_nothrow_move_constructible_v<_Err>)
622614
{

stl/inc/tuple

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -553,12 +553,11 @@ public:
553553
}
554554

555555
#if _HAS_CXX23
556-
template <class _Myself = tuple, class _This2 = _This,
557-
enable_if_t<conjunction_v<_STD _Is_copy_assignable_no_precondition_check<const _This2>,
558-
_STD _Is_copy_assignable_no_precondition_check<const _Rest>...>,
559-
int> = 0>
556+
template <class _Myself = tuple>
557+
requires conjunction_v<_STD _Is_copy_assignable_no_precondition_check<const _This>,
558+
_STD _Is_copy_assignable_no_precondition_check<const _Rest>...>
560559
constexpr const tuple& operator=(_Identity_t<const _Myself&> _Right) const
561-
noexcept(conjunction_v<is_nothrow_copy_assignable<const _This2>,
560+
noexcept(conjunction_v<is_nothrow_copy_assignable<const _This>,
562561
is_nothrow_copy_assignable<const _Rest>...>) /* strengthened */ {
563562
_Myfirst._Val = _Right._Myfirst._Val;
564563
_Get_rest() = _Right._Get_rest();
@@ -578,12 +577,11 @@ public:
578577
}
579578

580579
#if _HAS_CXX23
581-
template <class _Myself = tuple, class _This2 = _This,
582-
enable_if_t<conjunction_v<_STD _Is_assignable_no_precondition_check<const _This2&, _This2>,
583-
_STD _Is_assignable_no_precondition_check<const _Rest&, _Rest>...>,
584-
int> = 0>
580+
template <class _Myself = tuple>
581+
requires conjunction_v<_STD _Is_assignable_no_precondition_check<const _This&, _This>,
582+
_STD _Is_assignable_no_precondition_check<const _Rest&, _Rest>...>
585583
constexpr const tuple& operator=(_Identity_t<_Myself&&> _Right) const
586-
noexcept(conjunction_v<is_nothrow_assignable<const _This2&, _This2>,
584+
noexcept(conjunction_v<is_nothrow_assignable<const _This&, _This>,
587585
is_nothrow_assignable<const _Rest&, _Rest>...>) /* strengthened */ {
588586
_Myfirst._Val = _STD forward<_This>(_Right._Myfirst._Val);
589587
_Get_rest() = _STD forward<_Mybase>(_Right._Get_rest());
@@ -602,9 +600,8 @@ public:
602600
}
603601

604602
#if _HAS_CXX23
605-
template <class... _Other, enable_if_t<conjunction_v<_STD negation<_STD is_same<tuple, _STD tuple<_Other...>>>,
606-
_STD _Tuple_assignable_val<const tuple, const _Other&...>>,
607-
int> = 0>
603+
template <class... _Other>
604+
requires (!is_same_v<tuple, _STD tuple<_Other...>>) && _Tuple_assignable_v<const tuple, const _Other&...>
608605
constexpr const tuple& operator=(const tuple<_Other...>& _Right) const
609606
noexcept(_Tuple_nothrow_assignable_v<const tuple, const _Other&...>) /* strengthened */ {
610607
_Myfirst._Val = _Right._Myfirst._Val;
@@ -624,9 +621,8 @@ public:
624621
}
625622

626623
#if _HAS_CXX23
627-
template <class... _Other, enable_if_t<conjunction_v<_STD negation<_STD is_same<tuple, _STD tuple<_Other...>>>,
628-
_STD _Tuple_assignable_val<const tuple, _Other...>>,
629-
int> = 0>
624+
template <class... _Other>
625+
requires (!is_same_v<tuple, _STD tuple<_Other...>>) && _Tuple_assignable_v<const tuple, _Other...>
630626
constexpr const tuple& operator=(tuple<_Other...>&& _Right) const
631627
noexcept(_Tuple_nothrow_assignable_v<const tuple, _Other...>) /* strengthened */ {
632628
_Myfirst._Val = _STD forward<typename tuple<_Other...>::_This_type>(_Right._Myfirst._Val);
@@ -645,8 +641,8 @@ public:
645641
}
646642

647643
#if _HAS_CXX23
648-
template <class _First, class _Second,
649-
enable_if_t<_Tuple_assignable_v<const tuple, const _First&, const _Second&>, int> = 0>
644+
template <class _First, class _Second>
645+
requires _Tuple_assignable_v<const tuple, const _First&, const _Second&>
650646
constexpr const tuple& operator=(const pair<_First, _Second>& _Right) const
651647
noexcept(_Tuple_nothrow_assignable_v<const tuple, const _First&, const _Second&>) /* strengthened */ {
652648
_Myfirst._Val = _Right.first;
@@ -664,7 +660,8 @@ public:
664660
}
665661

666662
#if _HAS_CXX23
667-
template <class _First, class _Second, enable_if_t<_Tuple_assignable_v<const tuple, _First, _Second>, int> = 0>
663+
template <class _First, class _Second>
664+
requires _Tuple_assignable_v<const tuple, _First, _Second>
668665
constexpr const tuple& operator=(pair<_First, _Second>&& _Right) const
669666
noexcept(_Tuple_nothrow_assignable_v<const tuple, _First, _Second>) /* strengthened */ {
670667
_Myfirst._Val = _STD forward<_First>(_Right.first);
@@ -896,7 +893,8 @@ _CONSTEXPR20 void swap(tuple<_Types...>& _Left, tuple<_Types...>& _Right) noexce
896893
}
897894

898895
#if _HAS_CXX23
899-
_EXPORT_STD template <class... _Types, enable_if_t<conjunction_v<is_swappable<const _Types>...>, int> = 0>
896+
_EXPORT_STD template <class... _Types>
897+
requires conjunction_v<is_swappable<const _Types>...>
900898
constexpr void swap(const tuple<_Types...>& _Left, const tuple<_Types...>& _Right) noexcept(
901899
noexcept(_Left.swap(_Right))) {
902900
_Left.swap(_Right);

stl/inc/utility

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ struct pair { // store a pair of values
261261
pair(pair&&) = default;
262262

263263
#if _HAS_CXX23
264-
template <class _Other1, class _Other2,
265-
enable_if_t<conjunction_v<is_constructible<_Ty1, _Other1&>, is_constructible<_Ty2, _Other2&>>, int> = 0>
264+
template <class _Other1, class _Other2>
265+
requires is_constructible_v<_Ty1, _Other1&> && is_constructible_v<_Ty2, _Other2&>
266266
constexpr explicit(!conjunction_v<is_convertible<_Other1&, _Ty1>, is_convertible<_Other2&, _Ty2>>)
267267
pair(pair<_Other1, _Other2>& _Right) noexcept(
268268
is_nothrow_constructible_v<_Ty1, _Other1&> && is_nothrow_constructible_v<_Ty2, _Other2&>) // strengthened
@@ -286,9 +286,8 @@ struct pair { // store a pair of values
286286
: first(_STD forward<_Other1>(_Right.first)), second(_STD forward<_Other2>(_Right.second)) {}
287287

288288
#if _HAS_CXX23
289-
template <class _Other1, class _Other2,
290-
enable_if_t<conjunction_v<is_constructible<_Ty1, const _Other1>, is_constructible<_Ty2, const _Other2>>, int> =
291-
0>
289+
template <class _Other1, class _Other2>
290+
requires is_constructible_v<_Ty1, const _Other1> && is_constructible_v<_Ty2, const _Other2>
292291
constexpr explicit(!conjunction_v<is_convertible<const _Other1, _Ty1>, is_convertible<const _Other2, _Ty2>>)
293292
pair(const pair<_Other1, _Other2>&& _Right) noexcept(
294293
is_nothrow_constructible_v<_Ty1, const _Other1>
@@ -335,10 +334,9 @@ struct pair { // store a pair of values
335334
}
336335

337336
#if _HAS_CXX23
338-
template <class _Myself = pair,
339-
enable_if_t<conjunction_v<_Is_copy_assignable_no_precondition_check<const typename _Myself::first_type>,
340-
_Is_copy_assignable_no_precondition_check<const typename _Myself::second_type>>,
341-
int> = 0>
337+
template <class _Myself = pair>
338+
requires _Is_copy_assignable_unchecked_v<const typename _Myself::first_type>
339+
&& _Is_copy_assignable_unchecked_v<const typename _Myself::second_type>
342340
constexpr const pair& operator=(_Identity_t<const _Myself&> _Right) const
343341
noexcept(conjunction_v<is_nothrow_copy_assignable<const _Ty1>,
344342
is_nothrow_copy_assignable<const _Ty2>>) /* strengthened */ {
@@ -360,10 +358,9 @@ struct pair { // store a pair of values
360358
}
361359

362360
#if _HAS_CXX23
363-
template <class _Myself = pair,
364-
enable_if_t<conjunction_v<_Is_assignable_no_precondition_check<const typename _Myself::first_type&, _Ty1>,
365-
_Is_assignable_no_precondition_check<const typename _Myself::second_type&, _Ty2>>,
366-
int> = 0>
361+
template <class _Myself = pair>
362+
requires _Is_assignable_no_precondition_check<const typename _Myself::first_type&, _Ty1>::value
363+
&& _Is_assignable_no_precondition_check<const typename _Myself::second_type&, _Ty2>::value
367364
constexpr const pair& operator=(_Identity_t<_Myself&&> _Right) const
368365
noexcept(conjunction_v<is_nothrow_assignable<const _Ty1&, _Ty1>,
369366
is_nothrow_assignable<const _Ty2&, _Ty2>>) /* strengthened */ {
@@ -386,10 +383,9 @@ struct pair { // store a pair of values
386383
}
387384

388385
#if _HAS_CXX23
389-
template <class _Other1, class _Other2,
390-
enable_if_t<conjunction_v<negation<is_same<pair, pair<_Other1, _Other2>>>,
391-
is_assignable<const _Ty1&, const _Other1&>, is_assignable<const _Ty2&, const _Other2&>>,
392-
int> = 0>
386+
template <class _Other1, class _Other2>
387+
requires (!is_same_v<pair, pair<_Other1, _Other2>>)
388+
&& is_assignable_v<const _Ty1&, const _Other1&> && is_assignable_v<const _Ty2&, const _Other2&>
393389
constexpr const pair& operator=(const pair<_Other1, _Other2>& _Right) const
394390
noexcept(is_nothrow_assignable_v<const _Ty1&, const _Other1&>
395391
&& is_nothrow_assignable_v<const _Ty2&, const _Other2&>) /* strengthened */ {
@@ -411,10 +407,9 @@ struct pair { // store a pair of values
411407
}
412408

413409
#if _HAS_CXX23
414-
template <class _Other1, class _Other2,
415-
enable_if_t<conjunction_v<negation<is_same<pair, pair<_Other1, _Other2>>>, is_assignable<const _Ty1&, _Other1>,
416-
is_assignable<const _Ty2&, _Other2>>,
417-
int> = 0>
410+
template <class _Other1, class _Other2>
411+
requires (!is_same_v<pair, pair<_Other1, _Other2>>)
412+
&& is_assignable_v<const _Ty1&, _Other1> && is_assignable_v<const _Ty2&, _Other2>
418413
constexpr const pair& operator=(pair<_Other1, _Other2>&& _Right) const
419414
noexcept(is_nothrow_assignable_v<const _Ty1&, _Other1>
420415
&& is_nothrow_assignable_v<const _Ty2&, _Other2>) /* strengthened */ {
@@ -481,8 +476,8 @@ _CONSTEXPR20 void swap(pair<_Ty1, _Ty2>& _Left, pair<_Ty1, _Ty2>& _Right) noexce
481476
}
482477

483478
#if _HAS_CXX23
484-
_EXPORT_STD template <class _Ty1, class _Ty2,
485-
enable_if_t<is_swappable_v<const _Ty1> && is_swappable_v<const _Ty2>, int> = 0>
479+
_EXPORT_STD template <class _Ty1, class _Ty2>
480+
requires is_swappable<const _Ty1>::value && is_swappable<const _Ty2>::value // TRANSITION, /permissive needs ::value
486481
constexpr void swap(const pair<_Ty1, _Ty2>& _Left, const pair<_Ty1, _Ty2>& _Right) noexcept(
487482
noexcept(_Left.swap(_Right))) {
488483
_Left.swap(_Right);

0 commit comments

Comments
 (0)