Skip to content

Commit 9be881d

Browse files
add test
1 parent 08f2dd8 commit 9be881d

File tree

4 files changed

+85
-6
lines changed

4 files changed

+85
-6
lines changed

libcxx/test/std/ranges/range.adaptors/range.concat/ctor.verify.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515

1616
#include "test_macros.h"
1717

18-
struct NoSizeRange : std::ranges::view_base {
19-
constexpr auto size() { return 0; }
20-
};
18+
template <typename... Ts>
19+
concept ViewWithAtLeastOneElement = requires(Ts...&& a) { std::views::concat(a...); };
2120

2221
int main(int, char**) {
2322
{
@@ -36,9 +35,13 @@ int main(int, char**) {
3635
}
3736

3837
{
39-
// input is a view but has 0 size
40-
auto c = std::views::concat(NoSizeRange{});
41-
// expected-error@*:* {{}}
38+
// input is a view and has 0 size
39+
static_assert(!ViewWithAtLeastOneElement<>);
40+
}
41+
42+
{
43+
// input is a view and has at least an element
44+
static_assert(ViewWithAtLeastOneElement<std::vector<int>>);
4245
}
4346

4447
{

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@
88

99
// REQUIRES: std-at-least-c++26
1010

11+
// friend constexpr iterator operator-(const iterator& it, difference_type n)
12+
// requires concat-is-random-access<Const, Views...>;
13+
14+
// friend constexpr difference_type operator-(const iterator& x, const iterator& y)
15+
// requires concat-is-random-access<Const, Views...>;
16+
17+
// friend constexpr difference_type operator-(default_sentinel_t, const __iterator& __x)
18+
// requires(sized_sentinel_for<sentinel_t<__maybe_const<_Const, _Views>>, iterator_t<__maybe_const<_Const, _Views>>> &&
19+
// ...) &&
20+
// (__all_but_first_model_sized_range<_Const, _Views...>::value)
21+
22+
// friend constexpr difference_type operator-(const __iterator& __x, default_sentinel_t)
23+
// requires(sized_sentinel_for<sentinel_t<__maybe_const<_Const, _Views>>, iterator_t<__maybe_const<_Const, _Views>>> &&
24+
// ...) &&
25+
// (__all_but_first_model_sized_range<_Const, _Views...>::value)
26+
1127
#include <array>
1228
#include <concepts>
1329
#include <functional>
@@ -78,6 +94,26 @@ constexpr bool test() {
7894
assert((it1 - it2) == -11);
7995
}
8096

97+
{
98+
// operator-(sentinel, x)
99+
std::array<int, 2> array1{0, 1};
100+
std::array<int, 2> array2{2, 3};
101+
std::ranges::concat_view view(std::views::all(array1), std::views::all(array2));
102+
auto it1 = view.begin();
103+
auto res = std::default_sentinel_t{} - it1;
104+
assert(res == 4);
105+
}
106+
107+
{
108+
// operator-(x, sentinel)
109+
std::array<int, 2> array1{0, 1};
110+
std::array<int, 2> array2{2, 3};
111+
std::ranges::concat_view view(std::views::all(array1), std::views::all(array2));
112+
auto it1 = view.begin();
113+
auto res = it1 - std::default_sentinel_t{};
114+
assert(res == -4);
115+
}
116+
81117
{
82118
// One of the ranges is not random access
83119
std::ranges::concat_view v(a, b, ForwardSizedView{buffer1});

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
@@ -57,6 +57,23 @@ constexpr void test() {
5757
assert(*it1 == *it2);
5858
}
5959

60+
{
61+
// test with more than one view and iterators are in different range
62+
constexpr static std::array<int, 3> array1{0, 1, 2};
63+
constexpr static std::array<int, 3> array2{4, 5, 6};
64+
constexpr static std::ranges::concat_view view(std::views::all(array1), std::views::all(array2));
65+
decltype(auto) it1 = view.begin();
66+
decltype(auto) it2 = view.begin() + 3;
67+
68+
assert(it1 != it2);
69+
assert(*it1 = 0);
70+
assert(*it1 = 4);
71+
it1++;
72+
it2++;
73+
assert(*it1 = 1);
74+
assert(*it1 = 5);
75+
}
76+
6077
{
6178
std::array<int, 5> array{0, 1, 2, 3, 4};
6279
ConcatView view = make_concat_view(array.data(), array.data() + array.size());

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,29 @@ constexpr void test() {
5050
assert(*it1 == *it2);
5151
}
5252

53+
{
54+
// test with more than one view of different types
55+
using View = minimal_view<Iter, Sent>;
56+
using ConcatView = std::ranges::concat_view<View>;
57+
using ConcatIterator = std::ranges::iterator_t<ConcatView>;
58+
59+
auto make_concat_view = [](auto begin, auto end) {
60+
View view{Iter(begin), Sent(Iter(end))};
61+
return ConcatView(std::move(view));
62+
};
63+
64+
std::array<int, 3> array1{0, 1, 2};
65+
std::array<int, 3> array2{3, 4, 5};
66+
ConcatView view = make_concat_view(array1.data(), array1.data() + array1.size());
67+
std::ranges::concat_view cv(view, std::views::all(array2));
68+
decltype(auto) it1 = cv.begin();
69+
decltype(auto) it2 = cv.begin() + 3;
70+
71+
ASSERT_SAME_TYPE(int&, decltype(*it1));
72+
assert(*it1 == 0);
73+
assert(*it2 == 3);
74+
}
75+
5376
{
5477
// constness
5578
constexpr static std::array<int, 3> array1{0, 1, 2};

0 commit comments

Comments
 (0)