Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 25 additions & 19 deletions stl/inc/algorithm
Original file line number Diff line number Diff line change
Expand Up @@ -3430,6 +3430,11 @@ _FwdIt2 swap_ranges(_ExPo&&, _FwdIt1 _First1, _FwdIt1 _Last1, _FwdIt2 _Dest) noe
}
#endif // _HAS_CXX17

_EXPORT_STD template <class _FwdIt1, class _FwdIt2>
_CONSTEXPR20 void iter_swap(_FwdIt1 _Left, _FwdIt2 _Right) { // swap *_Left and *_Right
swap(*_Left, *_Right); // intentional ADL
}

_EXPORT_STD template <class _InIt, class _OutIt, class _Fn>
_CONSTEXPR20 _OutIt transform(const _InIt _First, const _InIt _Last, _OutIt _Dest, _Fn _Func) {
// transform [_First, _Last) with _Func
Expand Down Expand Up @@ -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
}
}
}
Expand Down Expand Up @@ -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
}
}
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -7924,14 +7929,14 @@ template <class _RanIt, class _Pr>
_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
}
}
}
Expand Down Expand Up @@ -7980,20 +7985,21 @@ _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;
}
}

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
}
}

Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion stl/inc/deque
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions stl/inc/execution
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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) {
Expand All @@ -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;
}
Expand Down
14 changes: 9 additions & 5 deletions stl/inc/expected
Original file line number Diff line number Diff line change
Expand Up @@ -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>)
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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) {
Expand All @@ -1361,14 +1364,15 @@ public:
_Has_value = true;
_Other._Has_value = false;
} else {
_Swap_adl(_Unexpected, _Other._Unexpected);
swap(_Unexpected, _Other._Unexpected); // intentional ADL
}
}

friend constexpr void swap(expected& _Left, expected& _Right) noexcept(
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) {
Expand All @@ -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
}
}

Expand Down
3 changes: 2 additions & 1 deletion stl/inc/forward_list
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
4 changes: 2 additions & 2 deletions stl/inc/hash_map
Original file line number Diff line number Diff line change
Expand Up @@ -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 <class _Kty, // key type
Expand Down Expand Up @@ -102,7 +101,8 @@ namespace stdext {
}

void swap(_Hmap_traits& _Rhs) noexcept(_Is_nothrow_swappable<_Tr>::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);
}

Expand Down
4 changes: 2 additions & 2 deletions stl/inc/hash_set
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ namespace stdext {
using _STD swap;
using _STD _Hash;
using _STD _Is_nothrow_swappable;
using _STD _Swap_adl;

template <class _Kty, // key type (same as value type)
class _Tr, // comparator predicate type
Expand Down Expand Up @@ -79,7 +78,8 @@ namespace stdext {
}

void swap(_Hset_traits& _Rhs) noexcept(_Is_nothrow_swappable<_Tr>::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);
}

Expand Down
3 changes: 2 additions & 1 deletion stl/inc/list
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
10 changes: 6 additions & 4 deletions stl/inc/memory
Original file line number Diff line number Diff line change
Expand Up @@ -3280,8 +3280,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 {
Expand Down Expand Up @@ -3418,8 +3419,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 {
Expand Down
3 changes: 2 additions & 1 deletion stl/inc/optional
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,15 @@ public:
"optional<T>::swap requires T to be move constructible (N4950 [optional.swap]/1).");
static_assert(!is_move_constructible_v<_Ty> || is_swappable_v<_Ty>,
"optional<T>::swap requires T to be swappable (N4950 [optional.swap]/2).");
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));
} else {
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;
Expand Down
8 changes: 5 additions & 3 deletions stl/inc/queue
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions stl/inc/regex
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -3135,8 +3136,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();
Expand Down
Loading