Skip to content

Commit 02bdf6c

Browse files
address LWG4166
1 parent cfb8b73 commit 02bdf6c

File tree

1 file changed

+31
-0
lines changed
  • libcxx/test/std/ranges/range.adaptors/range.concat

1 file changed

+31
-0
lines changed

libcxx/test/std/ranges/range.adaptors/range.concat/end.pass.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,37 @@ constexpr bool test() {
4747
static_assert(std::is_same_v<decltype(v.end()), std::default_sentinel_t>);
4848
}
4949

50+
{
51+
// all the ranges but the last one are input ranges, the last range is common => end() returns sentinel
52+
using Iter = cpp20_input_iterator<const int*>;
53+
using Sentinel = sentinel_wrapper<Iter>;
54+
using InputView = minimal_view<Iter, Sentinel>;
55+
56+
std::array<int, 3> arr{1, 2, 3};
57+
auto v = std::views::concat(InputView{Iter{buffer1}, Sentinel{Iter{buffer1 + 5}}}, arr);
58+
static_assert(std::same_as<decltype(v.end()), std::default_sentinel_t>);
59+
}
60+
61+
{
62+
// first range is forward range, the last range is common => end() does not return sentinel
63+
using Iter = forward_iterator<const int*>;
64+
using Sentinel = sentinel_wrapper<Iter>;
65+
using ForwardView = minimal_view<Iter, Sentinel>;
66+
67+
std::array<int, 2> arr{6, 7};
68+
auto v = std::views::concat(ForwardView{Iter{buffer1}, Sentinel{Iter{buffer1 + 5}}}, arr);
69+
static_assert(!std::same_as<decltype(v.end()), std::default_sentinel_t>);
70+
static_assert(std::same_as<decltype(v.end()), decltype(v.begin())>);
71+
72+
auto it = v.begin();
73+
auto last = v.end();
74+
int sum = 0;
75+
for (; it != last; it++) {
76+
sum += *it;
77+
}
78+
assert(sum == 1 + 2 + 3 + 4 + 5 + 6 + 7);
79+
}
80+
5081
return true;
5182
}
5283

0 commit comments

Comments
 (0)