Skip to content

Commit 6ba3737

Browse files
fix iterator test
1 parent 288955a commit 6ba3737

File tree

4 files changed

+69
-22
lines changed

4 files changed

+69
-22
lines changed

libcxx/test/std/ranges/range.adaptors/range.concat/iterator/compare.pass.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ constexpr void test() {
2929
};
3030

3131
{
32+
// test with one view
3233
std::array<int, 5> array{0, 1, 2, 3, 4};
3334
ConcatView view = make_concat_view(array.data(), array.data() + array.size());
3435
decltype(auto) it1 = view.begin();
@@ -40,6 +41,22 @@ constexpr void test() {
4041
assert(!(it1 == it2));
4142
}
4243

44+
{
45+
// test with more than one view
46+
constexpr static std::array<int, 3> array1{0, 1, 2};
47+
constexpr static std::array<int, 3> array2{0, 1, 2};
48+
constexpr static std::ranges::concat_view view(std::views::all(array1), std::views::all(array2));
49+
decltype(auto) it1 = view.begin();
50+
decltype(auto) it2 = view.begin();
51+
std::same_as<bool> decltype(auto) result = (it1 == it2);
52+
assert(result);
53+
54+
++it2; ++it2;
55+
assert(!(it1 == it2));
56+
++it2;
57+
assert(*it1 == *it2);
58+
}
59+
4360
{
4461
std::array<int, 5> array{0, 1, 2, 3, 4};
4562
ConcatView view = make_concat_view(array.data(), array.data() + array.size());

libcxx/test/std/ranges/range.adaptors/range.concat/iterator/decrement.pass.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,33 @@
1616
#include "../types.h"
1717

1818
constexpr void test() {
19-
// Test with a single satisfied value
19+
// Test with a single view
2020
{
2121
constexpr static std::array<int, 5> array{0, 1, 2, 3, 4};
2222
constexpr static std::ranges::concat_view view(std::views::all(array));
2323
auto it = std::ranges::next(view.begin(), view.end());
24-
assert(it == view.end()); // test the test
24+
assert(it == view.end());
2525

2626
auto& result = --it;
2727
ASSERT_SAME_TYPE(decltype(result)&, decltype(--it));
2828
assert(&result == &it);
2929
assert(result == view.begin() + 4);
3030
}
3131

32-
// Test with more than one satisfied value
32+
// Test with more than one view
3333
{
34-
constexpr static std::array<int, 5> array{0, 1, 2, 3, 4};
35-
constexpr static std::ranges::concat_view view(std::views::all(array));
34+
constexpr static std::array<int, 3> array{0, 1, 2};
35+
constexpr static std::array<int, 3> array1{3, 4, 5};
36+
constexpr std::ranges::concat_view view(std::views::all(array), std::views::all(array1));
3637
auto it = std::ranges::next(view.begin(), view.end());
37-
assert(it == view.end()); // test the test
38+
assert(it == view.end());
3839

3940
auto& result = --it;
4041
assert(&result == &it);
4142

4243
--it;
43-
assert(it == view.begin() + 3);
44+
assert(*it == 4);
45+
assert(it == view.begin() + 4);
4446
}
4547

4648
// Test going forward and then backward on the same iterator

libcxx/test/std/ranges/range.adaptors/range.concat/iterator/deref.pass.cpp

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,49 @@
1717

1818
template <class Iter, class ValueType = int, class Sent = sentinel_wrapper<Iter>>
1919
constexpr void test() {
20-
using View = minimal_view<Iter, Sent>;
21-
using ConcatView = std::ranges::concat_view<View>;
22-
using ConcatIterator = std::ranges::iterator_t<ConcatView>;
23-
24-
auto make_concat_view = [](auto begin, auto end) {
25-
View view{Iter(begin), Sent(Iter(end))};
26-
return ConcatView(std::move(view));
27-
};
28-
29-
std::array array{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
30-
ConcatView view = make_concat_view(array.data(), array.data() + array.size());
31-
ConcatIterator iter = view.begin();
32-
int& result = *iter;
33-
ASSERT_SAME_TYPE(int&, decltype(*iter));
34-
assert(&result == array.data());
20+
21+
{
22+
// test with one view
23+
using View = minimal_view<Iter, Sent>;
24+
using ConcatView = std::ranges::concat_view<View>;
25+
using ConcatIterator = std::ranges::iterator_t<ConcatView>;
26+
27+
auto make_concat_view = [](auto begin, auto end) {
28+
View view{Iter(begin), Sent(Iter(end))};
29+
return ConcatView(std::move(view));
30+
};
31+
32+
std::array array{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
33+
ConcatView view = make_concat_view(array.data(), array.data() + array.size());
34+
ConcatIterator iter = view.begin();
35+
int& result = *iter;
36+
ASSERT_SAME_TYPE(int&, decltype(*iter));
37+
assert(&result == array.data());
38+
}
39+
40+
{
41+
// test with more than one view
42+
std::array<int, 3> array1{0, 1, 2};
43+
std::array<int, 3> array2{0, 1, 2};
44+
std::ranges::concat_view view(std::views::all(array1), std::views::all(array2));
45+
decltype(auto) it1 = view.begin();
46+
decltype(auto) it2 = view.begin() + 3;
47+
48+
ASSERT_SAME_TYPE(int&, decltype(*it1));
49+
assert(*it1 == *it2);
50+
}
51+
52+
{
53+
// constness
54+
constexpr static std::array<int, 3> array1{0, 1, 2};
55+
constexpr static std::array<int, 3> array2{0, 1, 2};
56+
constexpr static std::ranges::concat_view view(std::views::all(array1), std::views::all(array2));
57+
decltype(auto) it1 = view.begin();
58+
decltype(auto) it2 = view.begin() + 3;
59+
60+
ASSERT_SAME_TYPE(const int&, decltype(*it1));
61+
assert(*it1 == *it2);
62+
}
3563
}
3664

3765
constexpr bool tests() {

0 commit comments

Comments
 (0)