]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Implement ranges::shift_left/right from P2440R1
authorPatrick Palka <ppalka@redhat.com>
Sun, 6 Jul 2025 18:49:34 +0000 (14:49 -0400)
committerPatrick Palka <ppalka@redhat.com>
Sun, 6 Jul 2025 18:49:34 +0000 (14:49 -0400)
commit2a56f3c539b782b15ee76d5752921800ccc53eef
tree2857414c7e542d80baa97123e3df3ae79ca9a1a0
parentbac45dda59cbd8419bd4513b1a76365825ac8307
libstdc++: Implement ranges::shift_left/right from P2440R1

The implementation is just a copy of std::shift_left/right with the
following changes:

 - check bidirectional_iterator instead of iterator_category
 - cope with __last being a distinct sentinel type
 - for shift_left, return the subrange {__first, X} instead of X
 - for shift_right, return the subrange {X, ranges::next(__first, __last)}
   instead of X
 - use the ranges:: versions of move_backward, move and iter_swap
 - don't bother std::move'ing any iterators, it's unnecessary since all
   iterators are forward, it's visually noisy, and in earlier versions
   of this patch it introduced subtle use-after-move bugs

In passing also use the __glibcxx_shift macro to guard the
std::shift_left/right implementations.

libstdc++-v3/ChangeLog:

* include/bits/ranges_algo.h (shift_left, shift_right): Guard
with __glibcxx_shift >= 201806L.
(ranges::__shift_left_fn, ranges::shift_left): Define for C++23.
(ranges::__shift_right_fn, ranges::shift_right): Likewise.
* include/bits/version.def (shift): Update for C++23.
* include/bits/version.h: Regenerate.
* src/c++23/std.cc.in: Add ranges::shift_left/right.
* testsuite/25_algorithms/shift_left/constrained.cc: New test,
based off of 1.cc.
* testsuite/25_algorithms/shift_right/constrained.cc: New test,
based off of 1.cc.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/include/bits/ranges_algo.h
libstdc++-v3/include/bits/version.def
libstdc++-v3/include/bits/version.h
libstdc++-v3/src/c++23/std.cc.in
libstdc++-v3/testsuite/25_algorithms/shift_left/constrained.cc [new file with mode: 0644]
libstdc++-v3/testsuite/25_algorithms/shift_right/constrained.cc [new file with mode: 0644]