Skip to content

Commit

Permalink
<algorithm>: Fix ranges::_Rotate_one_left (#2188)
Browse files Browse the repository at this point in the history
Co-authored-by: Stephan T. Lavavej <[email protected]>
  • Loading branch information
MattStephanson and StephanTLavavej authored Sep 11, 2021
1 parent 3d02211 commit 75e7d21
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion stl/inc/algorithm
Original file line number Diff line number Diff line change
Expand Up @@ -6667,7 +6667,7 @@ namespace ranges {
void _Rotate_one_left(_It _First, _It _Mid, _It _Last) {
// exchanges the range [_First, _Mid) with [_Mid, _Last)
_STL_INTERNAL_CHECK(_RANGES next(_First) == _Mid);
auto _Temp = _RANGES iter_move(_Mid);
auto _Temp = _RANGES iter_move(_First);
auto _Result = _RANGES _Move_unchecked(_STD move(_Mid), _STD move(_Last), _STD move(_First));
*_Result.out = _STD move(_Temp);
}
Expand Down
10 changes: 10 additions & 0 deletions tests/std/tests/P0896R4_ranges_alg_stable_sort/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ struct instantiator {
}
};

void test_gh2187() {
constexpr array orig{0, 1, 3, 2, 5, 6, 4, 7, 8, 12, 9, 10, 12, 11, 13, 14, 17, 15, 16, 24, 18, 21, 19, 20, 22, 25,
23, 26, 27, 28, 29, 30, 31};
auto v = orig;
ranges::stable_sort(v);
assert(is_sorted(v.begin(), v.end()));
assert(is_permutation(v.begin(), v.end(), orig.begin(), orig.end()));
}

int main() {
test_random<instantiator, P>();
test_gh2187();
}

0 comments on commit 75e7d21

Please sign in to comment.