Skip to content

Commit bfdc562

Browse files
[libc++] Fix copy-paste damage in ranges::rotate_copy and its test (#74544)
Found while running libc++'s tests with MSVC's STL. `ranges::rotate_copy` takes `forward_iterator`s as this test's comment banner correctly depicts. However, this test had bogus assertions expecting that `ranges::rotate_copy` would be constrained away for not-quite-**bidi** iterators. @philnik777 confirmed that these were copy-paste relics from the `ranges::reverse_copy` test. I fixed this by replacing the assertions with the test types that aren't quite **forward** iterators/ranges. Additionally, I noticed that the top-level `test()` function was missing coverage with the weakest possible `forward_iterator<int*>`. This revealed that the product code in `ranges_rotate_copy.h` was similarly damaged. In addition to fixing it by taking `forward_iterator` and `forward_range` as depicted in the Standard, this drops the inclusion of `<__iterator/reverse_iterator.h>` as this algorithm doesn't need `std::__reverse_range`.
1 parent fcd06d7 commit bfdc562

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

libcxx/include/__algorithm/ranges_rotate_copy.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <__algorithm/ranges_copy.h>
1414
#include <__config>
1515
#include <__iterator/concepts.h>
16-
#include <__iterator/reverse_iterator.h>
1716
#include <__ranges/access.h>
1817
#include <__ranges/concepts.h>
1918
#include <__ranges/dangling.h>
@@ -34,7 +33,7 @@ using rotate_copy_result = in_out_result<_InIter, _OutIter>;
3433

3534
namespace __rotate_copy {
3635
struct __fn {
37-
template <bidirectional_iterator _InIter, sentinel_for<_InIter> _Sent, weakly_incrementable _OutIter>
36+
template <forward_iterator _InIter, sentinel_for<_InIter> _Sent, weakly_incrementable _OutIter>
3837
requires indirectly_copyable<_InIter, _OutIter>
3938
_LIBCPP_HIDE_FROM_ABI constexpr rotate_copy_result<_InIter, _OutIter>
4039
operator()(_InIter __first, _InIter __middle, _Sent __last, _OutIter __result) const {
@@ -43,7 +42,7 @@ struct __fn {
4342
return {std::move(__res1.in), std::move(__res2.out)};
4443
}
4544

46-
template <bidirectional_range _Range, weakly_incrementable _OutIter>
45+
template <forward_range _Range, weakly_incrementable _OutIter>
4746
requires indirectly_copyable<iterator_t<_Range>, _OutIter>
4847
_LIBCPP_HIDE_FROM_ABI constexpr rotate_copy_result<borrowed_iterator_t<_Range>, _OutIter>
4948
operator()(_Range&& __range, iterator_t<_Range> __middle, _OutIter __result) const {

libcxx/test/std/algorithms/alg.modifying.operations/alg.rotate/ranges.rotate_copy.pass.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@ template <class Range, class Out = int*>
3434
concept HasRotateCopyR = requires(Range range, Out out) { std::ranges::rotate_copy(range, nullptr, out); };
3535

3636
static_assert(HasRotateCopyIt<int*>);
37-
static_assert(!HasRotateCopyIt<BidirectionalIteratorNotDerivedFrom>);
38-
static_assert(!HasRotateCopyIt<BidirectionalIteratorNotDecrementable>);
37+
static_assert(!HasRotateCopyIt<ForwardIteratorNotDerivedFrom>);
38+
static_assert(!HasRotateCopyIt<ForwardIteratorNotIncrementable>);
3939
static_assert(!HasRotateCopyIt<int*, SentinelForNotSemiregular>);
4040
static_assert(!HasRotateCopyIt<int*, SentinelForNotWeaklyEqualityComparableWith>);
4141
static_assert(!HasRotateCopyIt<int*, OutputIteratorNotIndirectlyWritable>);
4242
static_assert(!HasRotateCopyIt<int*, OutputIteratorNotInputOrOutputIterator>);
4343

4444
static_assert(HasRotateCopyR<UncheckedRange<int*>>);
45-
static_assert(!HasRotateCopyR<BidirectionalRangeNotDerivedFrom>);
46-
static_assert(!HasRotateCopyR<BidirectionalRangeNotDecrementable>);
45+
static_assert(!HasRotateCopyR<ForwardRangeNotDerivedFrom>);
46+
static_assert(!HasRotateCopyR<ForwardRangeNotIncrementable>);
4747
static_assert(!HasRotateCopyR<UncheckedRange<int*, SentinelForNotSemiregular>>);
4848
static_assert(!HasRotateCopyR<UncheckedRange<int*>, OutputIteratorNotIndirectlyWritable>);
4949
static_assert(!HasRotateCopyR<UncheckedRange<int*>, OutputIteratorNotInputOrOutputIterator>);
@@ -112,6 +112,7 @@ constexpr void test_out_iterators() {
112112
}
113113

114114
constexpr bool test() {
115+
test_out_iterators<forward_iterator<int*>>();
115116
test_out_iterators<bidirectional_iterator<int*>>();
116117
test_out_iterators<random_access_iterator<int*>>();
117118
test_out_iterators<contiguous_iterator<int*>>();

0 commit comments

Comments
 (0)