From 5c63219bcf12d00a82f06ac0fb17a54c54d20520 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Sun, 14 May 2023 23:41:23 +0800 Subject: [PATCH 1/5] Expand `std::iter_swap` and remove `_Swap_adl` Also - Move `std::iter_swap` from `` to ``. - In `_Partition_by_median_guess_unchecked`, only evaluate `_Prev_iter(_Glast)` once. --- stl/inc/algorithm | 44 ++++++++++++++++++++++++------------------ stl/inc/deque | 2 +- stl/inc/execution | 8 ++++---- stl/inc/expected | 10 +++++----- stl/inc/forward_list | 2 +- stl/inc/hash_map | 3 +-- stl/inc/hash_set | 3 +-- stl/inc/list | 2 +- stl/inc/memory | 8 ++++---- stl/inc/optional | 2 +- stl/inc/queue | 6 +++--- stl/inc/regex | 6 +++--- stl/inc/stack | 2 +- stl/inc/tuple | 4 ++-- stl/inc/utility | 20 +++++-------------- stl/inc/vector | 6 +++--- stl/inc/xhash | 4 ++-- stl/inc/xmemory | 2 +- stl/inc/xnode_handle.h | 2 +- stl/inc/xstring | 2 +- stl/inc/xtree | 4 ++-- stl/inc/xutility | 10 +++++----- 22 files changed, 73 insertions(+), 79 deletions(-) diff --git a/stl/inc/algorithm b/stl/inc/algorithm index 312e06b0a00..63cc39f0d15 100644 --- a/stl/inc/algorithm +++ b/stl/inc/algorithm @@ -3430,6 +3430,11 @@ _FwdIt2 swap_ranges(_ExPo&&, _FwdIt1 _First1, _FwdIt1 _Last1, _FwdIt2 _Dest) noe } #endif // _HAS_CXX17 +_EXPORT_STD template +_CONSTEXPR20 void iter_swap(_FwdIt1 _Left, _FwdIt2 _Right) { // swap *_Left and *_Right + swap(*_Left, *_Right); // intentional ADL +} + _EXPORT_STD template _CONSTEXPR20 _OutIt transform(const _InIt _First, const _InIt _Last, _OutIt _Dest, _Fn _Func) { // transform [_First, _Last) with _Func @@ -5349,7 +5354,7 @@ void _Random_shuffle1(_RanIt _First, _RanIt _Last, _RngFn& _RngFunc) { _Diff _Off = _RngFunc(static_cast<_Diff>(_Target_index + 1)); _STL_ASSERT(0 <= _Off && _Off <= _Target_index, "random value out of range"); if (_Off != _Target_index) { // avoid self-move-assignment - _STD iter_swap(_UTarget, _UFirst + _Off); + swap(*_UTarget, *(_UFirst + _Off)); // intentional ADL } } } @@ -5559,7 +5564,7 @@ constexpr _FwdIt shift_right(_FwdIt _First, const _FwdIt _Last, _Iter_diff_t<_Fw return _First; } - _Swap_adl(*_Mid, *_Trail); + swap(*_Mid, *_Trail); // intentional ADL } } } @@ -5830,7 +5835,7 @@ _CONSTEXPR20 _FwdIt partition(_FwdIt _First, const _FwdIt _Last, _Pr _Pred) { } } while (!_Pred(*_ULast)); - _STD iter_swap(_UFirst, _ULast); // out of place, swap and loop + swap(*_UFirst, *_ULast); // out of place, swap and loop; intentional ADL ++_UFirst; } } else { @@ -5849,7 +5854,7 @@ _CONSTEXPR20 _FwdIt partition(_FwdIt _First, const _FwdIt _Last, _Pr _Pred) { for (auto _UNext = _UFirst; ++_UNext != _ULast;) { if (_Pred(*_UNext)) { - _STD iter_swap(_UFirst, _UNext); // out of place, swap and loop + swap(*_UFirst, *_UNext); // out of place, swap and loop; intentional ADL ++_UFirst; } } @@ -7924,14 +7929,14 @@ template _CONSTEXPR20 void _Med3_unchecked(_RanIt _First, _RanIt _Mid, _RanIt _Last, _Pr _Pred) { // sort median of three elements to middle if (_DEBUG_LT_PRED(_Pred, *_Mid, *_First)) { - _STD iter_swap(_Mid, _First); + swap(*_Mid, *_First); // intentional ADL } if (_DEBUG_LT_PRED(_Pred, *_Last, *_Mid)) { // swap middle and last, then test first again - _STD iter_swap(_Last, _Mid); + swap(*_Last, *_Mid); // intentional ADL if (_DEBUG_LT_PRED(_Pred, *_Mid, *_First)) { - _STD iter_swap(_Mid, _First); + swap(*_Mid, *_First); // intentional ADL } } } @@ -7980,7 +7985,7 @@ _CONSTEXPR20 pair<_RanIt, _RanIt> _Partition_by_median_guess_unchecked(_RanIt _F } else if (_Pred(*_Gfirst, *_Pfirst)) { break; } else if (_Plast != _Gfirst) { - _STD iter_swap(_Plast, _Gfirst); + swap(*_Plast, *_Gfirst); // intentional ADL ++_Plast; } else { ++_Plast; @@ -7988,12 +7993,13 @@ _CONSTEXPR20 pair<_RanIt, _RanIt> _Partition_by_median_guess_unchecked(_RanIt _F } for (; _First < _Glast; --_Glast) { - if (_DEBUG_LT_PRED(_Pred, *_Prev_iter(_Glast), *_Pfirst)) { + const auto _Glast_prev = _Prev_iter(_Glast); + if (_DEBUG_LT_PRED(_Pred, *_Glast_prev, *_Pfirst)) { continue; - } else if (_Pred(*_Pfirst, *_Prev_iter(_Glast))) { + } else if (_Pred(*_Pfirst, *_Glast_prev)) { break; - } else if (--_Pfirst != _Prev_iter(_Glast)) { - _STD iter_swap(_Pfirst, _Prev_iter(_Glast)); + } else if (--_Pfirst != _Glast_prev) { + swap(*_Pfirst, *_Glast_prev); // intentional ADL } } @@ -8003,21 +8009,21 @@ _CONSTEXPR20 pair<_RanIt, _RanIt> _Partition_by_median_guess_unchecked(_RanIt _F if (_Glast == _First) { // no room at bottom, rotate pivot upward if (_Plast != _Gfirst) { - _STD iter_swap(_Pfirst, _Plast); + swap(*_Pfirst, *_Plast); // intentional ADL } ++_Plast; - _STD iter_swap(_Pfirst, _Gfirst); + swap(*_Pfirst, *_Gfirst); // intentional ADL ++_Pfirst; ++_Gfirst; } else if (_Gfirst == _Last) { // no room at top, rotate pivot downward if (--_Glast != --_Pfirst) { - _STD iter_swap(_Glast, _Pfirst); + swap(*_Glast, *_Pfirst); // intentional ADL } - _STD iter_swap(_Pfirst, --_Plast); + swap(*_Pfirst, *--_Plast); // intentional ADL } else { - _STD iter_swap(_Gfirst, --_Glast); + swap(*_Gfirst, *--_Glast); // intentional ADL ++_Gfirst; } } @@ -10217,7 +10223,7 @@ _CONSTEXPR20 bool next_permutation(_BidIt _First, _BidIt _Last, _Pr _Pred) { --_UMid; } while (!_DEBUG_LT_PRED(_Pred, *_UNext, *_UMid)); - _STD iter_swap(_UNext, _UMid); + swap(*_UNext, *_UMid); // intentional ADL _STD reverse(_UNext1, _ULast); return true; } @@ -10321,7 +10327,7 @@ _CONSTEXPR20 bool prev_permutation(_BidIt _First, _BidIt _Last, _Pr _Pred) { --_UMid; } while (!_DEBUG_LT_PRED(_Pred, *_UMid, *_UNext)); - _STD iter_swap(_UNext, _UMid); + swap(*_UNext, *_UMid); // intentional ADL _STD reverse(_UNext1, _ULast); return true; } diff --git a/stl/inc/deque b/stl/inc/deque index 1bbf465b2b9..184e3867fec 100644 --- a/stl/inc/deque +++ b/stl/inc/deque @@ -1460,7 +1460,7 @@ public: auto& _My_data = _Get_data(); auto& _Right_data = _Right._Get_data(); _My_data._Swap_proxy_and_iterators(_Right_data); - _Swap_adl(_My_data._Map, _Right_data._Map); + swap(_My_data._Map, _Right_data._Map); // intentional ADL _STD swap(_My_data._Mapsize, _Right_data._Mapsize); _STD swap(_My_data._Myoff, _Right_data._Myoff); _STD swap(_My_data._Mysize, _Right_data._Mysize); diff --git a/stl/inc/execution b/stl/inc/execution index 45ca79f8ec6..713e3fa83e0 100644 --- a/stl/inc/execution +++ b/stl/inc/execution @@ -3346,7 +3346,7 @@ pair<_FwdIt, _Iter_diff_t<_FwdIt>> _Partition_with_count_unchecked(_FwdIt _First } } while (!_Pred(*_Last)); - _STD iter_swap(_First, _Last); // out of place, swap and loop + swap(*_First, *_Last); // out of place, swap and loop; intentional ADL ++_First; ++_Trues; } @@ -3367,7 +3367,7 @@ pair<_FwdIt, _Iter_diff_t<_FwdIt>> _Partition_with_count_unchecked(_FwdIt _First for (_FwdIt _Next = _First; ++_Next != _Last;) { if (_Pred(*_Next)) { - _STD iter_swap(_First, _Next); // out of place, swap and loop + swap(*_First, *_Next); // out of place, swap and loop; intentional ADL ++_First; ++_Trues; } @@ -3387,7 +3387,7 @@ pair<_FwdIt, _Iter_diff_t<_FwdIt>> _Partition_swap_backward( while (_First != _Last) { --_Last; if (_Pred(*_Last)) { - _STD iter_swap(_Beginning_of_falses, _Last); + swap(*_Beginning_of_falses, *_Last); // intentional ADL ++_Beginning_of_falses; ++_Trues; if (_Beginning_of_falses == _First) { @@ -3399,7 +3399,7 @@ pair<_FwdIt, _Iter_diff_t<_FwdIt>> _Partition_swap_backward( } else { for (; _First != _Last; ++_First) { if (_Pred(*_First)) { - _STD iter_swap(_First, _Beginning_of_falses); + swap(*_First, *_Beginning_of_falses); // intentional ADL ++_Beginning_of_falses; ++_Trues; } diff --git a/stl/inc/expected b/stl/inc/expected index 93fbfcf0843..73ea20ace23 100644 --- a/stl/inc/expected +++ b/stl/inc/expected @@ -83,7 +83,7 @@ public: // [expected.un.swap] constexpr void swap(unexpected& _Other) noexcept(is_nothrow_swappable_v<_Err>) { static_assert(is_swappable_v<_Err>, "E must be swappable"); - _Swap_adl(_Unexpected, _Other._Unexpected); + swap(_Unexpected, _Other._Unexpected); // intentional ADL } friend constexpr void swap(unexpected& _Left, unexpected& _Right) noexcept(is_nothrow_swappable_v<_Err>) @@ -519,7 +519,7 @@ public: && (is_nothrow_move_constructible_v<_Ty> || is_nothrow_move_constructible_v<_Err>) { if (_Has_value && _Other._Has_value) { - _Swap_adl(_Value, _Other._Value); + swap(_Value, _Other._Value); // intentional ADL } else if (_Has_value) { if constexpr (is_nothrow_move_constructible_v<_Err>) { _Err _Tmp(_STD move(_Other._Unexpected)); @@ -560,7 +560,7 @@ public: } else if (_Other._Has_value) { _Other.swap(*this); } else { - _Swap_adl(_Unexpected, _Other._Unexpected); + swap(_Unexpected, _Other._Unexpected); // intentional ADL } } @@ -1361,7 +1361,7 @@ public: _Has_value = true; _Other._Has_value = false; } else { - _Swap_adl(_Unexpected, _Other._Unexpected); + swap(_Unexpected, _Other._Unexpected); // intentional ADL } } @@ -1386,7 +1386,7 @@ public: _Left._Has_value = true; _Right._Has_value = false; } else { - _Swap_adl(_Left._Unexpected, _Right._Unexpected); + swap(_Left._Unexpected, _Right._Unexpected); // intentional ADL } } diff --git a/stl/inc/forward_list b/stl/inc/forward_list index 66aada2d043..a753fe47d6d 100644 --- a/stl/inc/forward_list +++ b/stl/inc/forward_list @@ -1100,7 +1100,7 @@ public: if (this != _STD addressof(_Right)) { _Pocs(_Getal(), _Right._Getal()); _Swap_proxy_and_iterators(_Right); - _Swap_adl(_Mypair._Myval2._Myhead, _Right._Mypair._Myval2._Myhead); + swap(_Mypair._Myval2._Myhead, _Right._Mypair._Myval2._Myhead); // intentional ADL } } diff --git a/stl/inc/hash_map b/stl/inc/hash_map index 90031064daa..ea96338b38e 100644 --- a/stl/inc/hash_map +++ b/stl/inc/hash_map @@ -30,7 +30,6 @@ namespace stdext { using _STD swap; using _STD _Hash; using _STD _Is_nothrow_swappable; - using _STD _Swap_adl; using _STD _Xout_of_range; template ::value) { - _Swap_adl(static_cast<_Tr&>(*this), static_cast<_Tr&>(_Rhs)); + swap(static_cast<_Tr&>(*this), static_cast<_Tr&>(_Rhs)); // intentional ADL _STD swap(_Max_buckets, _Rhs._Max_buckets); } diff --git a/stl/inc/hash_set b/stl/inc/hash_set index d288f5ed3b2..27ba400afef 100644 --- a/stl/inc/hash_set +++ b/stl/inc/hash_set @@ -27,7 +27,6 @@ namespace stdext { using _STD swap; using _STD _Hash; using _STD _Is_nothrow_swappable; - using _STD _Swap_adl; template ::value) { - _Swap_adl(static_cast<_Tr&>(*this), static_cast<_Tr&>(_Rhs)); + swap(static_cast<_Tr&>(*this), static_cast<_Tr&>(_Rhs)); // intentional ADL _STD swap(_Max_buckets, _Rhs._Max_buckets); } diff --git a/stl/inc/list b/stl/inc/list index 0df30ff122d..6f778559efc 100644 --- a/stl/inc/list +++ b/stl/inc/list @@ -960,7 +960,7 @@ private: auto& _My_data = _Mypair._Myval2; auto& _Right_data = _Right._Mypair._Myval2; _My_data._Swap_proxy_and_iterators(_Right_data); - _Swap_adl(_My_data._Myhead, _Right_data._Myhead); + swap(_My_data._Myhead, _Right_data._Myhead); // intentional ADL _STD swap(_My_data._Mysize, _Right_data._Mysize); } diff --git a/stl/inc/memory b/stl/inc/memory index 658f3e78cdc..1c2c4727880 100644 --- a/stl/inc/memory +++ b/stl/inc/memory @@ -3278,8 +3278,8 @@ public: } _CONSTEXPR23 void swap(unique_ptr& _Right) noexcept { - _Swap_adl(_Mypair._Myval2, _Right._Mypair._Myval2); - _Swap_adl(_Mypair._Get_first(), _Right._Mypair._Get_first()); + swap(_Mypair._Myval2, _Right._Mypair._Myval2); // intentional ADL + swap(_Mypair._Get_first(), _Right._Mypair._Get_first()); // intentional ADL } _CONSTEXPR23 ~unique_ptr() noexcept { @@ -3416,8 +3416,8 @@ public: } _CONSTEXPR23 void swap(unique_ptr& _Right) noexcept { - _Swap_adl(_Mypair._Myval2, _Right._Mypair._Myval2); - _Swap_adl(_Mypair._Get_first(), _Right._Mypair._Get_first()); + swap(_Mypair._Myval2, _Right._Mypair._Myval2); // intentional ADL + swap(_Mypair._Get_first(), _Right._Mypair._Get_first()); // intentional ADL } _CONSTEXPR23 ~unique_ptr() noexcept { diff --git a/stl/inc/optional b/stl/inc/optional index 67678631108..aed8928a33c 100644 --- a/stl/inc/optional +++ b/stl/inc/optional @@ -358,7 +358,7 @@ public: const bool _Engaged = this->_Has_value; if (_Engaged == _Right._Has_value) { if (_Engaged) { - _Swap_adl(**this, *_Right); + swap(**this, *_Right); // intentional ADL } } else { optional& _Source = _Engaged ? *this : _Right; diff --git a/stl/inc/queue b/stl/inc/queue index 68d7ec4ab1f..00e83751c46 100644 --- a/stl/inc/queue +++ b/stl/inc/queue @@ -146,7 +146,7 @@ public: } void swap(queue& _Right) noexcept(_Is_nothrow_swappable<_Container>::value) { - _Swap_adl(c, _Right.c); + swap(c, _Right.c); // intentional ADL } _NODISCARD const _Container& _Get_container() const noexcept { @@ -405,8 +405,8 @@ public: void swap(priority_queue& _Right) noexcept( _Is_nothrow_swappable<_Container>::value&& _Is_nothrow_swappable<_Pr>::value) { - _Swap_adl(c, _Right.c); - _Swap_adl(comp, _Right.comp); + swap(c, _Right.c); // intentional ADL + swap(comp, _Right.comp); // intentional ADL } protected: diff --git a/stl/inc/regex b/stl/inc/regex index 7053b6173f8..ae856e7af5e 100644 --- a/stl/inc/regex +++ b/stl/inc/regex @@ -1138,7 +1138,7 @@ public: void swap(match_results& _Right) noexcept(_Is_nothrow_swappable<_BidIt>::value) /* strengthened */ { _STD swap(_Ready, _Right._Ready); - _Swap_adl(_Org, _Right._Org); + swap(_Org, _Right._Org); // intentional ADL _Matches.swap(_Right._Matches); _STD swap(_Prefix, _Right._Prefix); _STD swap(_Suffix, _Right._Suffix); @@ -3135,8 +3135,8 @@ void _Builder<_FwdIt, _Elem, _RxTraits>::_Add_rep(int _Min, int _Max, bool _Gree _Insert_node(_Pos, _If_expr); if (!_Greedy) { - _Swap_adl(_If_expr->_Next->_Prev, _If_empty_str->_Next->_Prev); - _Swap_adl(_If_expr->_Next, _If_empty_str->_Next); + swap(_If_expr->_Next->_Prev, _If_empty_str->_Next->_Prev); // intentional ADL + swap(_If_expr->_Next, _If_empty_str->_Next); // intentional ADL } } else { _Node_end_rep* _Node0 = new _Node_end_rep(); diff --git a/stl/inc/stack b/stl/inc/stack index d23c4305a56..2c7a66b7ae1 100644 --- a/stl/inc/stack +++ b/stl/inc/stack @@ -136,7 +136,7 @@ public: } void swap(stack& _Right) noexcept(_Is_nothrow_swappable<_Container>::value) { - _Swap_adl(c, _Right.c); + swap(c, _Right.c); // intentional ADL } _NODISCARD const _Container& _Get_container() const noexcept { diff --git a/stl/inc/tuple b/stl/inc/tuple index e1aaacbd28d..ac5110adcbe 100644 --- a/stl/inc/tuple +++ b/stl/inc/tuple @@ -733,7 +733,7 @@ public: _CONSTEXPR20 void swap(tuple& _Right) noexcept( conjunction_v<_Is_nothrow_swappable<_This>, _Is_nothrow_swappable<_Rest>...>) { - _Swap_adl(_Myfirst._Val, _Right._Myfirst._Val); + swap(_Myfirst._Val, _Right._Myfirst._Val); // intentional ADL _Mybase::swap(_Right._Get_rest()); } @@ -741,7 +741,7 @@ public: template // see GH-3013 constexpr void swap(const tuple& _Right) const noexcept(conjunction_v, is_nothrow_swappable...>) { - _Swap_adl(_Myfirst._Val, _Right._Myfirst._Val); + swap(_Myfirst._Val, _Right._Myfirst._Val); // intentional ADL _Mybase::swap(_Right._Get_rest()); } #endif // _HAS_CXX23 diff --git a/stl/inc/utility b/stl/inc/utility index d16740f2c73..e870c41db38 100644 --- a/stl/inc/utility +++ b/stl/inc/utility @@ -77,11 +77,6 @@ _NODISCARD constexpr _Ty(min)(initializer_list<_Ty>, _Pr); // implemented in _NODISCARD constexpr _Ty(min)(initializer_list<_Ty>); // implemented in -_EXPORT_STD template -_CONSTEXPR20 void iter_swap(_FwdIt1 _Left, _FwdIt2 _Right) { // swap *_Left and *_Right - swap(*_Left, *_Right); -} - _EXPORT_STD template ::value, int> /* = 0 */> _CONSTEXPR20 void swap(_Ty (&_Left)[_Size], _Ty (&_Right)[_Size]) noexcept(_Is_nothrow_swappable<_Ty>::value) { if (&_Left != &_Right) { @@ -89,7 +84,7 @@ _CONSTEXPR20 void swap(_Ty (&_Left)[_Size], _Ty (&_Right)[_Size]) noexcept(_Is_n _Ty* _Last1 = _First1 + _Size; _Ty* _First2 = _Right; for (; _First1 != _Last1; ++_First1, ++_First2) { - _STD iter_swap(_First1, _First2); + swap(*_First1, *_First2); // intentional ADL } } } @@ -106,11 +101,6 @@ _CONSTEXPR20 void swap(_Ty& _Left, _Ty& _Right) noexcept( _Right = _STD move(_Tmp); } -template -_CONSTEXPR20 void _Swap_adl(_Ty& _Left, _Ty& _Right) noexcept(_Is_nothrow_swappable<_Ty>::value) { - swap(_Left, _Right); -} - _EXPORT_STD struct piecewise_construct_t { // tag type for pair tuple arguments explicit piecewise_construct_t() = default; }; @@ -445,8 +435,8 @@ struct pair { // store a pair of values _CONSTEXPR20 void swap(pair& _Right) noexcept( _Is_nothrow_swappable<_Ty1>::value&& _Is_nothrow_swappable<_Ty2>::value) { if (this != _STD addressof(_Right)) { - _Swap_adl(first, _Right.first); - _Swap_adl(second, _Right.second); + swap(first, _Right.first); // intentional ADL + swap(second, _Right.second); // intentional ADL } } @@ -455,8 +445,8 @@ struct pair { // store a pair of values constexpr void swap(const pair& _Right) const noexcept(is_nothrow_swappable_v&& is_nothrow_swappable_v) { if (this != _STD addressof(_Right)) { - _Swap_adl(first, _Right.first); - _Swap_adl(second, _Right.second); + swap(first, _Right.first); // intentional ADL + swap(second, _Right.second); // intentional ADL } } #endif // _HAS_CXX23 diff --git a/stl/inc/vector b/stl/inc/vector index 1d8ec8a59d6..22d9e76b71e 100644 --- a/stl/inc/vector +++ b/stl/inc/vector @@ -402,9 +402,9 @@ public: _CONSTEXPR20 void _Swap_val(_Vector_val& _Right) noexcept { this->_Swap_proxy_and_iterators(_Right); - _Swap_adl(_Myfirst, _Right._Myfirst); - _Swap_adl(_Mylast, _Right._Mylast); - _Swap_adl(_Myend, _Right._Myend); + swap(_Myfirst, _Right._Myfirst); // intentional ADL + swap(_Mylast, _Right._Mylast); // intentional ADL + swap(_Myend, _Right._Myend); // intentional ADL } _CONSTEXPR20 void _Take_contents(_Vector_val& _Right) noexcept { diff --git a/stl/inc/xhash b/stl/inc/xhash index f5af82fbd7c..4cb5ff28981 100644 --- a/stl/inc/xhash +++ b/stl/inc/xhash @@ -164,10 +164,10 @@ public: void swap(_Uhash_compare& _Rhs) noexcept( conjunction_v<_Is_nothrow_swappable<_Hasher>, _Is_nothrow_swappable<_Keyeq>>) { - _Swap_adl(_Mypair._Get_first(), _Rhs._Mypair._Get_first()); + swap(_Mypair._Get_first(), _Rhs._Mypair._Get_first()); // intentional ADL auto& _Lsecond = _Mypair._Myval2; auto& _Rsecond = _Rhs._Mypair._Myval2; - _Swap_adl(_Lsecond._Get_first(), _Rsecond._Get_first()); + swap(_Lsecond._Get_first(), _Rsecond._Get_first()); // intentional ADL _STD swap(_Lsecond._Myval2, _Rsecond._Myval2); } diff --git a/stl/inc/xmemory b/stl/inc/xmemory index d527dd705c8..8c4e42fa0d5 100644 --- a/stl/inc/xmemory +++ b/stl/inc/xmemory @@ -1072,7 +1072,7 @@ _CONSTEXPR20 void _Pocma(_Alloc& _Left, _Alloc& _Right) noexcept { // (maybe) pr template _CONSTEXPR20 void _Pocs(_Alloc& _Left, _Alloc& _Right) noexcept { if constexpr (allocator_traits<_Alloc>::propagate_on_container_swap::value) { - _Swap_adl(_Left, _Right); + swap(_Left, _Right); // intentional ADL } else { _STL_ASSERT(_Left == _Right, "containers incompatible for swap"); } diff --git a/stl/inc/xnode_handle.h b/stl/inc/xnode_handle.h index e6e7627bbe8..ebb2900840b 100644 --- a/stl/inc/xnode_handle.h +++ b/stl/inc/xnode_handle.h @@ -192,7 +192,7 @@ class _Node_handle : public _Base<_Node_handle<_Node, _Alloc, _Base, _Types...>, _Construct_in_place(_Getal(), _STD move(_That_al)); _Destroy_in_place(_That_al); } - _Swap_adl(_Ptr, _That._Ptr); + swap(_Ptr, _That._Ptr); // intentional ADL } friend void swap(_Node_handle& _Left, _Node_handle& _Right) noexcept /* strengthened */ { _Left.swap(_Right); diff --git a/stl/inc/xstring b/stl/inc/xstring index aacda3476e5..3bbd3a92e45 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -4286,7 +4286,7 @@ public: #endif // !defined(_INSERT_STRING_ANNOTATION) if (_My_large && _Right_large) { // swap buffers, iterators preserved - _Swap_adl(_My_data._Bx._Ptr, _Right_data._Bx._Ptr); + swap(_My_data._Bx._Ptr, _Right_data._Bx._Ptr); // intentional ADL } else if (_My_large) { // swap large with small _Swap_bx_large_with_small(_My_data, _Right_data); } else if (_Right_large) { // swap small with large diff --git a/stl/inc/xtree b/stl/inc/xtree index 14ad1d7e056..0714cffec3a 100644 --- a/stl/inc/xtree +++ b/stl/inc/xtree @@ -985,7 +985,7 @@ private: const auto _Scary = _Get_scary(); const auto _Right_scary = _Right._Get_scary(); _Scary->_Swap_proxy_and_iterators(*_Right_scary); - _Swap_adl(_Scary->_Myhead, _Right_scary->_Myhead); + swap(_Scary->_Myhead, _Right_scary->_Myhead); // intentional ADL _STD swap(_Scary->_Mysize, _Right_scary->_Mysize); } @@ -1485,7 +1485,7 @@ public: if (this != _STD addressof(_Right)) { _Pocs(_Getal(), _Right._Getal()); _Swap_val_excluding_comp(_Right); - _Swap_adl(_Getcomp(), _Right._Getcomp()); + swap(_Getcomp(), _Right._Getcomp()); // intentional ADL } } diff --git a/stl/inc/xutility b/stl/inc/xutility index 9ed0ea2df90..ebf8aeb7528 100644 --- a/stl/inc/xutility +++ b/stl/inc/xutility @@ -6316,7 +6316,7 @@ _CONSTEXPR20 void reverse(const _BidIt _First, const _BidIt _Last) { // reverse #endif // _USE_STD_VECTOR_ALGORITHMS for (; _UFirst != _ULast && _UFirst != --_ULast; ++_UFirst) { - _STD iter_swap(_UFirst, _ULast); + swap(*_UFirst, *_ULast); // intentional ADL } } @@ -6333,7 +6333,7 @@ template constexpr pair<_BidIt, _BidIt> _Reverse_until_sentinel_unchecked(_BidIt _First, _BidIt _Sentinel, _BidIt _Last) { // reverse until either _First or _Last hits _Sentinel while (_First != _Sentinel && _Last != _Sentinel) { - _STD iter_swap(_First, --_Last); + swap(*_First, *--_Last); // intentional ADL ++_First; } @@ -6372,7 +6372,7 @@ _CONSTEXPR20 _FwdIt rotate(_FwdIt _First, _FwdIt _Mid, _FwdIt _Last) { } else { auto _UNext = _UMid; do { // rotate the first cycle - _STD iter_swap(_UFirst, _UNext); + swap(*_UFirst, *_UNext); // intentional ADL ++_UFirst; ++_UNext; if (_UFirst == _UMid) { @@ -6383,7 +6383,7 @@ _CONSTEXPR20 _FwdIt rotate(_FwdIt _First, _FwdIt _Mid, _FwdIt _Last) { while (_UMid != _ULast) { // rotate subsequent cycles _UNext = _UMid; do { - _STD iter_swap(_UFirst, _UNext); + swap(*_UFirst, *_UNext); // intentional ADL ++_UFirst; ++_UNext; if (_UFirst == _UMid) { @@ -7202,7 +7202,7 @@ _CONSTEXPR20 _FwdIt2 _Swap_ranges_unchecked(_FwdIt1 _First1, const _FwdIt1 _Last #endif // _USE_STD_VECTOR_ALGORITHMS for (; _First1 != _Last1; ++_First1, (void) ++_First2) { - _STD iter_swap(_First1, _First2); + swap(*_First1, *_First2); // intentional ADL } return _First2; From 108b903b0c37f987b21e076bcc59e108d1e4a6f6 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Mon, 15 May 2023 00:25:32 +0800 Subject: [PATCH 2/5] Revert some changes due to member `swap` functions --- stl/inc/deque | 2 +- stl/inc/expected | 8 ++++---- stl/inc/forward_list | 2 +- stl/inc/hash_map | 3 ++- stl/inc/hash_set | 3 ++- stl/inc/list | 2 +- stl/inc/memory | 8 ++++---- stl/inc/optional | 2 +- stl/inc/queue | 6 +++--- stl/inc/regex | 6 +++--- stl/inc/stack | 2 +- stl/inc/tuple | 4 ++-- stl/inc/utility | 13 +++++++++---- stl/inc/vector | 6 +++--- stl/inc/xhash | 4 ++-- stl/inc/xnode_handle.h | 2 +- stl/inc/xstring | 2 +- stl/inc/xtree | 4 ++-- 18 files changed, 43 insertions(+), 36 deletions(-) diff --git a/stl/inc/deque b/stl/inc/deque index 184e3867fec..1bbf465b2b9 100644 --- a/stl/inc/deque +++ b/stl/inc/deque @@ -1460,7 +1460,7 @@ public: auto& _My_data = _Get_data(); auto& _Right_data = _Right._Get_data(); _My_data._Swap_proxy_and_iterators(_Right_data); - swap(_My_data._Map, _Right_data._Map); // intentional ADL + _Swap_adl(_My_data._Map, _Right_data._Map); _STD swap(_My_data._Mapsize, _Right_data._Mapsize); _STD swap(_My_data._Myoff, _Right_data._Myoff); _STD swap(_My_data._Mysize, _Right_data._Mysize); diff --git a/stl/inc/expected b/stl/inc/expected index 73ea20ace23..a2f2a2f9768 100644 --- a/stl/inc/expected +++ b/stl/inc/expected @@ -83,7 +83,7 @@ public: // [expected.un.swap] constexpr void swap(unexpected& _Other) noexcept(is_nothrow_swappable_v<_Err>) { static_assert(is_swappable_v<_Err>, "E must be swappable"); - swap(_Unexpected, _Other._Unexpected); // intentional ADL + _Swap_adl(_Unexpected, _Other._Unexpected); } friend constexpr void swap(unexpected& _Left, unexpected& _Right) noexcept(is_nothrow_swappable_v<_Err>) @@ -519,7 +519,7 @@ public: && (is_nothrow_move_constructible_v<_Ty> || is_nothrow_move_constructible_v<_Err>) { if (_Has_value && _Other._Has_value) { - swap(_Value, _Other._Value); // intentional ADL + _Swap_adl(_Value, _Other._Value); } else if (_Has_value) { if constexpr (is_nothrow_move_constructible_v<_Err>) { _Err _Tmp(_STD move(_Other._Unexpected)); @@ -560,7 +560,7 @@ public: } else if (_Other._Has_value) { _Other.swap(*this); } else { - swap(_Unexpected, _Other._Unexpected); // intentional ADL + _Swap_adl(_Unexpected, _Other._Unexpected); } } @@ -1361,7 +1361,7 @@ public: _Has_value = true; _Other._Has_value = false; } else { - swap(_Unexpected, _Other._Unexpected); // intentional ADL + _Swap_adl(_Unexpected, _Other._Unexpected); } } diff --git a/stl/inc/forward_list b/stl/inc/forward_list index a753fe47d6d..66aada2d043 100644 --- a/stl/inc/forward_list +++ b/stl/inc/forward_list @@ -1100,7 +1100,7 @@ public: if (this != _STD addressof(_Right)) { _Pocs(_Getal(), _Right._Getal()); _Swap_proxy_and_iterators(_Right); - swap(_Mypair._Myval2._Myhead, _Right._Mypair._Myval2._Myhead); // intentional ADL + _Swap_adl(_Mypair._Myval2._Myhead, _Right._Mypair._Myval2._Myhead); } } diff --git a/stl/inc/hash_map b/stl/inc/hash_map index ea96338b38e..90031064daa 100644 --- a/stl/inc/hash_map +++ b/stl/inc/hash_map @@ -30,6 +30,7 @@ namespace stdext { using _STD swap; using _STD _Hash; using _STD _Is_nothrow_swappable; + using _STD _Swap_adl; using _STD _Xout_of_range; template ::value) { - swap(static_cast<_Tr&>(*this), static_cast<_Tr&>(_Rhs)); // intentional ADL + _Swap_adl(static_cast<_Tr&>(*this), static_cast<_Tr&>(_Rhs)); _STD swap(_Max_buckets, _Rhs._Max_buckets); } diff --git a/stl/inc/hash_set b/stl/inc/hash_set index 27ba400afef..d288f5ed3b2 100644 --- a/stl/inc/hash_set +++ b/stl/inc/hash_set @@ -27,6 +27,7 @@ namespace stdext { using _STD swap; using _STD _Hash; using _STD _Is_nothrow_swappable; + using _STD _Swap_adl; template ::value) { - swap(static_cast<_Tr&>(*this), static_cast<_Tr&>(_Rhs)); // intentional ADL + _Swap_adl(static_cast<_Tr&>(*this), static_cast<_Tr&>(_Rhs)); _STD swap(_Max_buckets, _Rhs._Max_buckets); } diff --git a/stl/inc/list b/stl/inc/list index 6f778559efc..0df30ff122d 100644 --- a/stl/inc/list +++ b/stl/inc/list @@ -960,7 +960,7 @@ private: auto& _My_data = _Mypair._Myval2; auto& _Right_data = _Right._Mypair._Myval2; _My_data._Swap_proxy_and_iterators(_Right_data); - swap(_My_data._Myhead, _Right_data._Myhead); // intentional ADL + _Swap_adl(_My_data._Myhead, _Right_data._Myhead); _STD swap(_My_data._Mysize, _Right_data._Mysize); } diff --git a/stl/inc/memory b/stl/inc/memory index 1c2c4727880..658f3e78cdc 100644 --- a/stl/inc/memory +++ b/stl/inc/memory @@ -3278,8 +3278,8 @@ public: } _CONSTEXPR23 void swap(unique_ptr& _Right) noexcept { - swap(_Mypair._Myval2, _Right._Mypair._Myval2); // intentional ADL - swap(_Mypair._Get_first(), _Right._Mypair._Get_first()); // intentional ADL + _Swap_adl(_Mypair._Myval2, _Right._Mypair._Myval2); + _Swap_adl(_Mypair._Get_first(), _Right._Mypair._Get_first()); } _CONSTEXPR23 ~unique_ptr() noexcept { @@ -3416,8 +3416,8 @@ public: } _CONSTEXPR23 void swap(unique_ptr& _Right) noexcept { - swap(_Mypair._Myval2, _Right._Mypair._Myval2); // intentional ADL - swap(_Mypair._Get_first(), _Right._Mypair._Get_first()); // intentional ADL + _Swap_adl(_Mypair._Myval2, _Right._Mypair._Myval2); + _Swap_adl(_Mypair._Get_first(), _Right._Mypair._Get_first()); } _CONSTEXPR23 ~unique_ptr() noexcept { diff --git a/stl/inc/optional b/stl/inc/optional index aed8928a33c..67678631108 100644 --- a/stl/inc/optional +++ b/stl/inc/optional @@ -358,7 +358,7 @@ public: const bool _Engaged = this->_Has_value; if (_Engaged == _Right._Has_value) { if (_Engaged) { - swap(**this, *_Right); // intentional ADL + _Swap_adl(**this, *_Right); } } else { optional& _Source = _Engaged ? *this : _Right; diff --git a/stl/inc/queue b/stl/inc/queue index 00e83751c46..68d7ec4ab1f 100644 --- a/stl/inc/queue +++ b/stl/inc/queue @@ -146,7 +146,7 @@ public: } void swap(queue& _Right) noexcept(_Is_nothrow_swappable<_Container>::value) { - swap(c, _Right.c); // intentional ADL + _Swap_adl(c, _Right.c); } _NODISCARD const _Container& _Get_container() const noexcept { @@ -405,8 +405,8 @@ public: void swap(priority_queue& _Right) noexcept( _Is_nothrow_swappable<_Container>::value&& _Is_nothrow_swappable<_Pr>::value) { - swap(c, _Right.c); // intentional ADL - swap(comp, _Right.comp); // intentional ADL + _Swap_adl(c, _Right.c); + _Swap_adl(comp, _Right.comp); } protected: diff --git a/stl/inc/regex b/stl/inc/regex index ae856e7af5e..7053b6173f8 100644 --- a/stl/inc/regex +++ b/stl/inc/regex @@ -1138,7 +1138,7 @@ public: void swap(match_results& _Right) noexcept(_Is_nothrow_swappable<_BidIt>::value) /* strengthened */ { _STD swap(_Ready, _Right._Ready); - swap(_Org, _Right._Org); // intentional ADL + _Swap_adl(_Org, _Right._Org); _Matches.swap(_Right._Matches); _STD swap(_Prefix, _Right._Prefix); _STD swap(_Suffix, _Right._Suffix); @@ -3135,8 +3135,8 @@ void _Builder<_FwdIt, _Elem, _RxTraits>::_Add_rep(int _Min, int _Max, bool _Gree _Insert_node(_Pos, _If_expr); if (!_Greedy) { - swap(_If_expr->_Next->_Prev, _If_empty_str->_Next->_Prev); // intentional ADL - swap(_If_expr->_Next, _If_empty_str->_Next); // intentional ADL + _Swap_adl(_If_expr->_Next->_Prev, _If_empty_str->_Next->_Prev); + _Swap_adl(_If_expr->_Next, _If_empty_str->_Next); } } else { _Node_end_rep* _Node0 = new _Node_end_rep(); diff --git a/stl/inc/stack b/stl/inc/stack index 2c7a66b7ae1..d23c4305a56 100644 --- a/stl/inc/stack +++ b/stl/inc/stack @@ -136,7 +136,7 @@ public: } void swap(stack& _Right) noexcept(_Is_nothrow_swappable<_Container>::value) { - swap(c, _Right.c); // intentional ADL + _Swap_adl(c, _Right.c); } _NODISCARD const _Container& _Get_container() const noexcept { diff --git a/stl/inc/tuple b/stl/inc/tuple index ac5110adcbe..e1aaacbd28d 100644 --- a/stl/inc/tuple +++ b/stl/inc/tuple @@ -733,7 +733,7 @@ public: _CONSTEXPR20 void swap(tuple& _Right) noexcept( conjunction_v<_Is_nothrow_swappable<_This>, _Is_nothrow_swappable<_Rest>...>) { - swap(_Myfirst._Val, _Right._Myfirst._Val); // intentional ADL + _Swap_adl(_Myfirst._Val, _Right._Myfirst._Val); _Mybase::swap(_Right._Get_rest()); } @@ -741,7 +741,7 @@ public: template // see GH-3013 constexpr void swap(const tuple& _Right) const noexcept(conjunction_v, is_nothrow_swappable...>) { - swap(_Myfirst._Val, _Right._Myfirst._Val); // intentional ADL + _Swap_adl(_Myfirst._Val, _Right._Myfirst._Val); _Mybase::swap(_Right._Get_rest()); } #endif // _HAS_CXX23 diff --git a/stl/inc/utility b/stl/inc/utility index e870c41db38..3cd423bda97 100644 --- a/stl/inc/utility +++ b/stl/inc/utility @@ -101,6 +101,11 @@ _CONSTEXPR20 void swap(_Ty& _Left, _Ty& _Right) noexcept( _Right = _STD move(_Tmp); } +template +_CONSTEXPR20 void _Swap_adl(_Ty& _Left, _Ty& _Right) noexcept(_Is_nothrow_swappable<_Ty>::value) { + swap(_Left, _Right); // intentional ADL +} + _EXPORT_STD struct piecewise_construct_t { // tag type for pair tuple arguments explicit piecewise_construct_t() = default; }; @@ -435,8 +440,8 @@ struct pair { // store a pair of values _CONSTEXPR20 void swap(pair& _Right) noexcept( _Is_nothrow_swappable<_Ty1>::value&& _Is_nothrow_swappable<_Ty2>::value) { if (this != _STD addressof(_Right)) { - swap(first, _Right.first); // intentional ADL - swap(second, _Right.second); // intentional ADL + _Swap_adl(first, _Right.first); + _Swap_adl(second, _Right.second); } } @@ -445,8 +450,8 @@ struct pair { // store a pair of values constexpr void swap(const pair& _Right) const noexcept(is_nothrow_swappable_v&& is_nothrow_swappable_v) { if (this != _STD addressof(_Right)) { - swap(first, _Right.first); // intentional ADL - swap(second, _Right.second); // intentional ADL + _Swap_adl(first, _Right.first); + _Swap_adl(second, _Right.second); } } #endif // _HAS_CXX23 diff --git a/stl/inc/vector b/stl/inc/vector index 22d9e76b71e..1d8ec8a59d6 100644 --- a/stl/inc/vector +++ b/stl/inc/vector @@ -402,9 +402,9 @@ public: _CONSTEXPR20 void _Swap_val(_Vector_val& _Right) noexcept { this->_Swap_proxy_and_iterators(_Right); - swap(_Myfirst, _Right._Myfirst); // intentional ADL - swap(_Mylast, _Right._Mylast); // intentional ADL - swap(_Myend, _Right._Myend); // intentional ADL + _Swap_adl(_Myfirst, _Right._Myfirst); + _Swap_adl(_Mylast, _Right._Mylast); + _Swap_adl(_Myend, _Right._Myend); } _CONSTEXPR20 void _Take_contents(_Vector_val& _Right) noexcept { diff --git a/stl/inc/xhash b/stl/inc/xhash index 4cb5ff28981..f5af82fbd7c 100644 --- a/stl/inc/xhash +++ b/stl/inc/xhash @@ -164,10 +164,10 @@ public: void swap(_Uhash_compare& _Rhs) noexcept( conjunction_v<_Is_nothrow_swappable<_Hasher>, _Is_nothrow_swappable<_Keyeq>>) { - swap(_Mypair._Get_first(), _Rhs._Mypair._Get_first()); // intentional ADL + _Swap_adl(_Mypair._Get_first(), _Rhs._Mypair._Get_first()); auto& _Lsecond = _Mypair._Myval2; auto& _Rsecond = _Rhs._Mypair._Myval2; - swap(_Lsecond._Get_first(), _Rsecond._Get_first()); // intentional ADL + _Swap_adl(_Lsecond._Get_first(), _Rsecond._Get_first()); _STD swap(_Lsecond._Myval2, _Rsecond._Myval2); } diff --git a/stl/inc/xnode_handle.h b/stl/inc/xnode_handle.h index ebb2900840b..e6e7627bbe8 100644 --- a/stl/inc/xnode_handle.h +++ b/stl/inc/xnode_handle.h @@ -192,7 +192,7 @@ class _Node_handle : public _Base<_Node_handle<_Node, _Alloc, _Base, _Types...>, _Construct_in_place(_Getal(), _STD move(_That_al)); _Destroy_in_place(_That_al); } - swap(_Ptr, _That._Ptr); // intentional ADL + _Swap_adl(_Ptr, _That._Ptr); } friend void swap(_Node_handle& _Left, _Node_handle& _Right) noexcept /* strengthened */ { _Left.swap(_Right); diff --git a/stl/inc/xstring b/stl/inc/xstring index 3bbd3a92e45..aacda3476e5 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -4286,7 +4286,7 @@ public: #endif // !defined(_INSERT_STRING_ANNOTATION) if (_My_large && _Right_large) { // swap buffers, iterators preserved - swap(_My_data._Bx._Ptr, _Right_data._Bx._Ptr); // intentional ADL + _Swap_adl(_My_data._Bx._Ptr, _Right_data._Bx._Ptr); } else if (_My_large) { // swap large with small _Swap_bx_large_with_small(_My_data, _Right_data); } else if (_Right_large) { // swap small with large diff --git a/stl/inc/xtree b/stl/inc/xtree index 0714cffec3a..14ad1d7e056 100644 --- a/stl/inc/xtree +++ b/stl/inc/xtree @@ -985,7 +985,7 @@ private: const auto _Scary = _Get_scary(); const auto _Right_scary = _Right._Get_scary(); _Scary->_Swap_proxy_and_iterators(*_Right_scary); - swap(_Scary->_Myhead, _Right_scary->_Myhead); // intentional ADL + _Swap_adl(_Scary->_Myhead, _Right_scary->_Myhead); _STD swap(_Scary->_Mysize, _Right_scary->_Mysize); } @@ -1485,7 +1485,7 @@ public: if (this != _STD addressof(_Right)) { _Pocs(_Getal(), _Right._Getal()); _Swap_val_excluding_comp(_Right); - swap(_Getcomp(), _Right._Getcomp()); // intentional ADL + _Swap_adl(_Getcomp(), _Right._Getcomp()); } } From ab19bde6e36643d84ea858a5afb499744ee2ba76 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Mon, 15 May 2023 00:47:53 +0800 Subject: [PATCH 3/5] Reversion in `expected`'s friend `swap` function --- stl/inc/expected | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/expected b/stl/inc/expected index a2f2a2f9768..93fbfcf0843 100644 --- a/stl/inc/expected +++ b/stl/inc/expected @@ -1386,7 +1386,7 @@ public: _Left._Has_value = true; _Right._Has_value = false; } else { - swap(_Left._Unexpected, _Right._Unexpected); // intentional ADL + _Swap_adl(_Left._Unexpected, _Right._Unexpected); } } From cdf32de33e88c77e7d7e4a49adeed047e4e3493e Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Mon, 15 May 2023 09:23:26 +0800 Subject: [PATCH 4/5] `using _STD swap;` and remove `_Swap_adl` again --- stl/inc/deque | 3 ++- stl/inc/expected | 14 +++++++++----- stl/inc/forward_list | 3 ++- stl/inc/hash_map | 4 ++-- stl/inc/hash_set | 4 ++-- stl/inc/list | 3 ++- stl/inc/memory | 10 ++++++---- stl/inc/optional | 3 ++- stl/inc/queue | 8 +++++--- stl/inc/regex | 8 +++++--- stl/inc/stack | 3 ++- stl/inc/tuple | 6 ++++-- stl/inc/utility | 15 ++++++--------- stl/inc/vector | 7 ++++--- stl/inc/xhash | 5 +++-- stl/inc/xnode_handle.h | 3 ++- stl/inc/xstring | 4 +++- stl/inc/xtree | 6 ++++-- 18 files changed, 65 insertions(+), 44 deletions(-) diff --git a/stl/inc/deque b/stl/inc/deque index 1bbf465b2b9..2fd2956fc3d 100644 --- a/stl/inc/deque +++ b/stl/inc/deque @@ -1455,12 +1455,13 @@ public: } void swap(deque& _Right) noexcept /* strengthened */ { + using _STD swap; if (this != _STD addressof(_Right)) { _Pocs(_Getal(), _Right._Getal()); auto& _My_data = _Get_data(); auto& _Right_data = _Right._Get_data(); _My_data._Swap_proxy_and_iterators(_Right_data); - _Swap_adl(_My_data._Map, _Right_data._Map); + swap(_My_data._Map, _Right_data._Map); // intentional ADL _STD swap(_My_data._Mapsize, _Right_data._Mapsize); _STD swap(_My_data._Myoff, _Right_data._Myoff); _STD swap(_My_data._Mysize, _Right_data._Mysize); diff --git a/stl/inc/expected b/stl/inc/expected index 93fbfcf0843..30bc4550731 100644 --- a/stl/inc/expected +++ b/stl/inc/expected @@ -83,7 +83,8 @@ public: // [expected.un.swap] constexpr void swap(unexpected& _Other) noexcept(is_nothrow_swappable_v<_Err>) { static_assert(is_swappable_v<_Err>, "E must be swappable"); - _Swap_adl(_Unexpected, _Other._Unexpected); + using _STD swap; + swap(_Unexpected, _Other._Unexpected); // intentional ADL } friend constexpr void swap(unexpected& _Left, unexpected& _Right) noexcept(is_nothrow_swappable_v<_Err>) @@ -518,8 +519,9 @@ public: && is_move_constructible_v<_Ty> && is_move_constructible_v<_Err> // && (is_nothrow_move_constructible_v<_Ty> || is_nothrow_move_constructible_v<_Err>) { + using _STD swap; if (_Has_value && _Other._Has_value) { - _Swap_adl(_Value, _Other._Value); + swap(_Value, _Other._Value); // intentional ADL } else if (_Has_value) { if constexpr (is_nothrow_move_constructible_v<_Err>) { _Err _Tmp(_STD move(_Other._Unexpected)); @@ -560,7 +562,7 @@ public: } else if (_Other._Has_value) { _Other.swap(*this); } else { - _Swap_adl(_Unexpected, _Other._Unexpected); + swap(_Unexpected, _Other._Unexpected); // intentional ADL } } @@ -1344,6 +1346,7 @@ public: is_nothrow_move_constructible_v<_Err>&& is_nothrow_swappable_v<_Err>) // requires is_swappable_v<_Err> && is_move_constructible_v<_Err> { + using _STD swap; if (_Has_value && _Other._Has_value) { // nothing } else if (_Has_value) { @@ -1361,7 +1364,7 @@ public: _Has_value = true; _Other._Has_value = false; } else { - _Swap_adl(_Unexpected, _Other._Unexpected); + swap(_Unexpected, _Other._Unexpected); // intentional ADL } } @@ -1369,6 +1372,7 @@ public: is_nothrow_move_constructible_v<_Err>&& is_nothrow_swappable_v<_Err>) requires is_swappable_v<_Err> && is_move_constructible_v<_Err> { + using _STD swap; if (_Left._Has_value && _Right._Has_value) { // nothing } else if (_Left._Has_value) { @@ -1386,7 +1390,7 @@ public: _Left._Has_value = true; _Right._Has_value = false; } else { - _Swap_adl(_Left._Unexpected, _Right._Unexpected); + swap(_Left._Unexpected, _Right._Unexpected); // intentional ADL } } diff --git a/stl/inc/forward_list b/stl/inc/forward_list index 66aada2d043..aefc8c2437d 100644 --- a/stl/inc/forward_list +++ b/stl/inc/forward_list @@ -1097,10 +1097,11 @@ public: } void swap(forward_list& _Right) noexcept /* strengthened */ { + using _STD swap; if (this != _STD addressof(_Right)) { _Pocs(_Getal(), _Right._Getal()); _Swap_proxy_and_iterators(_Right); - _Swap_adl(_Mypair._Myval2._Myhead, _Right._Mypair._Myval2._Myhead); + swap(_Mypair._Myval2._Myhead, _Right._Mypair._Myval2._Myhead); // intentional ADL } } diff --git a/stl/inc/hash_map b/stl/inc/hash_map index 90031064daa..421dcb857b4 100644 --- a/stl/inc/hash_map +++ b/stl/inc/hash_map @@ -30,7 +30,6 @@ namespace stdext { using _STD swap; using _STD _Hash; using _STD _Is_nothrow_swappable; - using _STD _Swap_adl; using _STD _Xout_of_range; template ::value) { - _Swap_adl(static_cast<_Tr&>(*this), static_cast<_Tr&>(_Rhs)); + using _STD swap; + swap(static_cast<_Tr&>(*this), static_cast<_Tr&>(_Rhs)); // intentional ADL _STD swap(_Max_buckets, _Rhs._Max_buckets); } diff --git a/stl/inc/hash_set b/stl/inc/hash_set index d288f5ed3b2..f375a4b2ab0 100644 --- a/stl/inc/hash_set +++ b/stl/inc/hash_set @@ -27,7 +27,6 @@ namespace stdext { using _STD swap; using _STD _Hash; using _STD _Is_nothrow_swappable; - using _STD _Swap_adl; template ::value) { - _Swap_adl(static_cast<_Tr&>(*this), static_cast<_Tr&>(_Rhs)); + using _STD swap; + swap(static_cast<_Tr&>(*this), static_cast<_Tr&>(_Rhs)); // intentional ADL _STD swap(_Max_buckets, _Rhs._Max_buckets); } diff --git a/stl/inc/list b/stl/inc/list index 0df30ff122d..de5c25248ca 100644 --- a/stl/inc/list +++ b/stl/inc/list @@ -957,10 +957,11 @@ public: private: void _Swap_val(list& _Right) noexcept { // swap with _Right, same allocator + using _STD swap; auto& _My_data = _Mypair._Myval2; auto& _Right_data = _Right._Mypair._Myval2; _My_data._Swap_proxy_and_iterators(_Right_data); - _Swap_adl(_My_data._Myhead, _Right_data._Myhead); + swap(_My_data._Myhead, _Right_data._Myhead); // intentional ADL _STD swap(_My_data._Mysize, _Right_data._Mysize); } diff --git a/stl/inc/memory b/stl/inc/memory index 658f3e78cdc..dccd24795db 100644 --- a/stl/inc/memory +++ b/stl/inc/memory @@ -3278,8 +3278,9 @@ public: } _CONSTEXPR23 void swap(unique_ptr& _Right) noexcept { - _Swap_adl(_Mypair._Myval2, _Right._Mypair._Myval2); - _Swap_adl(_Mypair._Get_first(), _Right._Mypair._Get_first()); + using _STD swap; + swap(_Mypair._Myval2, _Right._Mypair._Myval2); // intentional ADL + swap(_Mypair._Get_first(), _Right._Mypair._Get_first()); // intentional ADL } _CONSTEXPR23 ~unique_ptr() noexcept { @@ -3416,8 +3417,9 @@ public: } _CONSTEXPR23 void swap(unique_ptr& _Right) noexcept { - _Swap_adl(_Mypair._Myval2, _Right._Mypair._Myval2); - _Swap_adl(_Mypair._Get_first(), _Right._Mypair._Get_first()); + using _STD swap; + swap(_Mypair._Myval2, _Right._Mypair._Myval2); // intentional ADL + swap(_Mypair._Get_first(), _Right._Mypair._Get_first()); // intentional ADL } _CONSTEXPR23 ~unique_ptr() noexcept { diff --git a/stl/inc/optional b/stl/inc/optional index 67678631108..5f1bb9f9dd9 100644 --- a/stl/inc/optional +++ b/stl/inc/optional @@ -351,6 +351,7 @@ public: "optional::swap requires T to be move constructible (N4828 [optional.swap]/1)."); static_assert(!is_move_constructible_v<_Ty> || is_swappable_v<_Ty>, "optional::swap requires T to be swappable (N4828 [optional.swap]/1)."); + using _STD swap; if constexpr (_Is_trivially_swappable_v<_Ty>) { using _TrivialBaseTy = _Optional_destruct_base<_Ty>; _STD swap(static_cast<_TrivialBaseTy&>(*this), static_cast<_TrivialBaseTy&>(_Right)); @@ -358,7 +359,7 @@ public: const bool _Engaged = this->_Has_value; if (_Engaged == _Right._Has_value) { if (_Engaged) { - _Swap_adl(**this, *_Right); + swap(**this, *_Right); // intentional ADL } } else { optional& _Source = _Engaged ? *this : _Right; diff --git a/stl/inc/queue b/stl/inc/queue index 68d7ec4ab1f..3ce80378b8e 100644 --- a/stl/inc/queue +++ b/stl/inc/queue @@ -146,7 +146,8 @@ public: } void swap(queue& _Right) noexcept(_Is_nothrow_swappable<_Container>::value) { - _Swap_adl(c, _Right.c); + using _STD swap; + swap(c, _Right.c); // intentional ADL } _NODISCARD const _Container& _Get_container() const noexcept { @@ -405,8 +406,9 @@ public: void swap(priority_queue& _Right) noexcept( _Is_nothrow_swappable<_Container>::value&& _Is_nothrow_swappable<_Pr>::value) { - _Swap_adl(c, _Right.c); - _Swap_adl(comp, _Right.comp); + using _STD swap; + swap(c, _Right.c); // intentional ADL + swap(comp, _Right.comp); // intentional ADL } protected: diff --git a/stl/inc/regex b/stl/inc/regex index 7053b6173f8..34f1afc6d6e 100644 --- a/stl/inc/regex +++ b/stl/inc/regex @@ -1137,8 +1137,9 @@ public: } void swap(match_results& _Right) noexcept(_Is_nothrow_swappable<_BidIt>::value) /* strengthened */ { + using _STD swap; _STD swap(_Ready, _Right._Ready); - _Swap_adl(_Org, _Right._Org); + swap(_Org, _Right._Org); // intentional ADL _Matches.swap(_Right._Matches); _STD swap(_Prefix, _Right._Prefix); _STD swap(_Suffix, _Right._Suffix); @@ -3135,8 +3136,9 @@ void _Builder<_FwdIt, _Elem, _RxTraits>::_Add_rep(int _Min, int _Max, bool _Gree _Insert_node(_Pos, _If_expr); if (!_Greedy) { - _Swap_adl(_If_expr->_Next->_Prev, _If_empty_str->_Next->_Prev); - _Swap_adl(_If_expr->_Next, _If_empty_str->_Next); + using _STD swap; + swap(_If_expr->_Next->_Prev, _If_empty_str->_Next->_Prev); // intentional ADL + swap(_If_expr->_Next, _If_empty_str->_Next); // intentional ADL } } else { _Node_end_rep* _Node0 = new _Node_end_rep(); diff --git a/stl/inc/stack b/stl/inc/stack index d23c4305a56..a007be90b52 100644 --- a/stl/inc/stack +++ b/stl/inc/stack @@ -136,7 +136,8 @@ public: } void swap(stack& _Right) noexcept(_Is_nothrow_swappable<_Container>::value) { - _Swap_adl(c, _Right.c); + using _STD swap; + swap(c, _Right.c); // intentional ADL } _NODISCARD const _Container& _Get_container() const noexcept { diff --git a/stl/inc/tuple b/stl/inc/tuple index e1aaacbd28d..29f95d783f6 100644 --- a/stl/inc/tuple +++ b/stl/inc/tuple @@ -733,7 +733,8 @@ public: _CONSTEXPR20 void swap(tuple& _Right) noexcept( conjunction_v<_Is_nothrow_swappable<_This>, _Is_nothrow_swappable<_Rest>...>) { - _Swap_adl(_Myfirst._Val, _Right._Myfirst._Val); + using _STD swap; + swap(_Myfirst._Val, _Right._Myfirst._Val); // intentional ADL _Mybase::swap(_Right._Get_rest()); } @@ -741,7 +742,8 @@ public: template // see GH-3013 constexpr void swap(const tuple& _Right) const noexcept(conjunction_v, is_nothrow_swappable...>) { - _Swap_adl(_Myfirst._Val, _Right._Myfirst._Val); + using _STD swap; + swap(_Myfirst._Val, _Right._Myfirst._Val); // intentional ADL _Mybase::swap(_Right._Get_rest()); } #endif // _HAS_CXX23 diff --git a/stl/inc/utility b/stl/inc/utility index 3cd423bda97..3864699cc29 100644 --- a/stl/inc/utility +++ b/stl/inc/utility @@ -101,11 +101,6 @@ _CONSTEXPR20 void swap(_Ty& _Left, _Ty& _Right) noexcept( _Right = _STD move(_Tmp); } -template -_CONSTEXPR20 void _Swap_adl(_Ty& _Left, _Ty& _Right) noexcept(_Is_nothrow_swappable<_Ty>::value) { - swap(_Left, _Right); // intentional ADL -} - _EXPORT_STD struct piecewise_construct_t { // tag type for pair tuple arguments explicit piecewise_construct_t() = default; }; @@ -439,9 +434,10 @@ struct pair { // store a pair of values _CONSTEXPR20 void swap(pair& _Right) noexcept( _Is_nothrow_swappable<_Ty1>::value&& _Is_nothrow_swappable<_Ty2>::value) { + using _STD swap; if (this != _STD addressof(_Right)) { - _Swap_adl(first, _Right.first); - _Swap_adl(second, _Right.second); + swap(first, _Right.first); // intentional ADL + swap(second, _Right.second); // intentional ADL } } @@ -449,9 +445,10 @@ struct pair { // store a pair of values template // see GH-3013 constexpr void swap(const pair& _Right) const noexcept(is_nothrow_swappable_v&& is_nothrow_swappable_v) { + using _STD swap; if (this != _STD addressof(_Right)) { - _Swap_adl(first, _Right.first); - _Swap_adl(second, _Right.second); + swap(first, _Right.first); // intentional ADL + swap(second, _Right.second); // intentional ADL } } #endif // _HAS_CXX23 diff --git a/stl/inc/vector b/stl/inc/vector index 1d8ec8a59d6..663a06b3caa 100644 --- a/stl/inc/vector +++ b/stl/inc/vector @@ -401,10 +401,11 @@ public: : _Myfirst(_First), _Mylast(_Last), _Myend(_End) {} _CONSTEXPR20 void _Swap_val(_Vector_val& _Right) noexcept { + using _STD swap; this->_Swap_proxy_and_iterators(_Right); - _Swap_adl(_Myfirst, _Right._Myfirst); - _Swap_adl(_Mylast, _Right._Mylast); - _Swap_adl(_Myend, _Right._Myend); + swap(_Myfirst, _Right._Myfirst); // intentional ADL + swap(_Mylast, _Right._Mylast); // intentional ADL + swap(_Myend, _Right._Myend); // intentional ADL } _CONSTEXPR20 void _Take_contents(_Vector_val& _Right) noexcept { diff --git a/stl/inc/xhash b/stl/inc/xhash index f5af82fbd7c..2bf7a9b9553 100644 --- a/stl/inc/xhash +++ b/stl/inc/xhash @@ -164,10 +164,11 @@ public: void swap(_Uhash_compare& _Rhs) noexcept( conjunction_v<_Is_nothrow_swappable<_Hasher>, _Is_nothrow_swappable<_Keyeq>>) { - _Swap_adl(_Mypair._Get_first(), _Rhs._Mypair._Get_first()); + using _STD swap; + swap(_Mypair._Get_first(), _Rhs._Mypair._Get_first()); // intentional ADL auto& _Lsecond = _Mypair._Myval2; auto& _Rsecond = _Rhs._Mypair._Myval2; - _Swap_adl(_Lsecond._Get_first(), _Rsecond._Get_first()); + swap(_Lsecond._Get_first(), _Rsecond._Get_first()); // intentional ADL _STD swap(_Lsecond._Myval2, _Rsecond._Myval2); } diff --git a/stl/inc/xnode_handle.h b/stl/inc/xnode_handle.h index e6e7627bbe8..ebd87f7095d 100644 --- a/stl/inc/xnode_handle.h +++ b/stl/inc/xnode_handle.h @@ -175,6 +175,7 @@ class _Node_handle : public _Base<_Node_handle<_Node, _Alloc, _Base, _Types...>, } void swap(_Node_handle& _That) noexcept /* strengthened */ { + using _STD swap; if (_Ptr != nullptr) { if (_That._Ptr != nullptr) { _Pocs(_Getal(), _That._Getal()); @@ -192,7 +193,7 @@ class _Node_handle : public _Base<_Node_handle<_Node, _Alloc, _Base, _Types...>, _Construct_in_place(_Getal(), _STD move(_That_al)); _Destroy_in_place(_That_al); } - _Swap_adl(_Ptr, _That._Ptr); + swap(_Ptr, _That._Ptr); // intentional ADL } friend void swap(_Node_handle& _Left, _Node_handle& _Right) noexcept /* strengthened */ { _Left.swap(_Right); diff --git a/stl/inc/xstring b/stl/inc/xstring index aacda3476e5..401db927f34 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -4259,6 +4259,8 @@ public: } _CONSTEXPR20 void _Swap_data(basic_string& _Right) { + using _STD swap; + auto& _My_data = _Mypair._Myval2; auto& _Right_data = _Right._Mypair._Myval2; @@ -4286,7 +4288,7 @@ public: #endif // !defined(_INSERT_STRING_ANNOTATION) if (_My_large && _Right_large) { // swap buffers, iterators preserved - _Swap_adl(_My_data._Bx._Ptr, _Right_data._Bx._Ptr); + swap(_My_data._Bx._Ptr, _Right_data._Bx._Ptr); // intentional ADL } else if (_My_large) { // swap large with small _Swap_bx_large_with_small(_My_data, _Right_data); } else if (_Right_large) { // swap small with large diff --git a/stl/inc/xtree b/stl/inc/xtree index 14ad1d7e056..639185e6395 100644 --- a/stl/inc/xtree +++ b/stl/inc/xtree @@ -982,10 +982,11 @@ public: private: void _Swap_val_excluding_comp(_Tree& _Right) { // swap contents (except comparator) with _Right, equal allocators + using _STD swap; const auto _Scary = _Get_scary(); const auto _Right_scary = _Right._Get_scary(); _Scary->_Swap_proxy_and_iterators(*_Right_scary); - _Swap_adl(_Scary->_Myhead, _Right_scary->_Myhead); + swap(_Scary->_Myhead, _Right_scary->_Myhead); // intentional ADL _STD swap(_Scary->_Mysize, _Right_scary->_Mysize); } @@ -1482,10 +1483,11 @@ public: } void swap(_Tree& _Right) noexcept(_Is_nothrow_swappable::value) /* strengthened */ { + using _STD swap; if (this != _STD addressof(_Right)) { _Pocs(_Getal(), _Right._Getal()); _Swap_val_excluding_comp(_Right); - _Swap_adl(_Getcomp(), _Right._Getcomp()); + swap(_Getcomp(), _Right._Getcomp()); // intentional ADL } } From 07cbd8fb05c21aaa941effabdb8b0ac225d0a241 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Mon, 15 May 2023 09:33:20 -0700 Subject: [PATCH 5/5] Drop `using _STD swap;` for `_Builder`, `_Vector_val`. --- stl/inc/regex | 1 - stl/inc/vector | 1 - 2 files changed, 2 deletions(-) diff --git a/stl/inc/regex b/stl/inc/regex index 34f1afc6d6e..cd2ea570493 100644 --- a/stl/inc/regex +++ b/stl/inc/regex @@ -3136,7 +3136,6 @@ void _Builder<_FwdIt, _Elem, _RxTraits>::_Add_rep(int _Min, int _Max, bool _Gree _Insert_node(_Pos, _If_expr); if (!_Greedy) { - using _STD swap; swap(_If_expr->_Next->_Prev, _If_empty_str->_Next->_Prev); // intentional ADL swap(_If_expr->_Next, _If_empty_str->_Next); // intentional ADL } diff --git a/stl/inc/vector b/stl/inc/vector index 663a06b3caa..22d9e76b71e 100644 --- a/stl/inc/vector +++ b/stl/inc/vector @@ -401,7 +401,6 @@ public: : _Myfirst(_First), _Mylast(_Last), _Myend(_End) {} _CONSTEXPR20 void _Swap_val(_Vector_val& _Right) noexcept { - using _STD swap; this->_Swap_proxy_and_iterators(_Right); swap(_Myfirst, _Right._Myfirst); // intentional ADL swap(_Mylast, _Right._Mylast); // intentional ADL