]>
Commit | Line | Data |
---|---|---|
cba9ef06 PP |
1 | // Copyright (C) 2020 Free Software Foundation, Inc. |
2 | // | |
3 | // This file is part of the GNU ISO C++ Library. This library is free | |
4 | // software; you can redistribute it and/or modify it under the | |
5 | // terms of the GNU General Public License as published by the | |
6 | // Free Software Foundation; either version 3, or (at your option) | |
7 | // any later version. | |
8 | ||
9 | // This library is distributed in the hope that it will be useful, | |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | // GNU General Public License for more details. | |
13 | ||
14 | // You should have received a copy of the GNU General Public License along | |
15 | // with this library; see the file COPYING3. If not see | |
16 | // <http://www.gnu.org/licenses/>. | |
17 | ||
18 | // { dg-options "-std=gnu++2a" } | |
19 | // { dg-do run { target c++2a } } | |
20 | ||
21 | #include <algorithm> | |
22 | #include <ranges> | |
23 | #include <string> | |
24 | #include <string_view> | |
25 | #include <vector> | |
26 | #include <testsuite_hooks.h> | |
27 | #include <testsuite_iterators.h> | |
28 | ||
29 | namespace ranges = std::ranges; | |
30 | namespace views = std::ranges::views; | |
31 | ||
32 | void | |
33 | test01() | |
34 | { | |
35 | using namespace std::literals; | |
36 | std::string_view cs[] = {"the", "quick", "brown", "fox"}; | |
37 | auto v = cs | views::join; | |
38 | VERIFY( ranges::equal(v, "thequickbrownfox"sv) ); | |
39 | using R = decltype(v); | |
40 | static_assert(ranges::bidirectional_range<R>); | |
41 | static_assert(ranges::bidirectional_range<const R>); | |
42 | static_assert(ranges::common_range<R>); | |
43 | static_assert(ranges::common_range<const R>); | |
44 | } | |
45 | ||
46 | void | |
47 | test02() | |
48 | { | |
49 | auto v = (views::iota(0,4) | |
50 | | views::transform([] (int i) { return views::iota(0,i); }) | |
51 | | views::join); | |
52 | VERIFY( ranges::equal(v, (int[]){0,0,1,0,1,2}) ); | |
53 | using R = decltype(v); | |
54 | static_assert(ranges::input_range<R>); | |
55 | static_assert(!ranges::range<const R>); | |
56 | static_assert(!ranges::forward_range<R>); | |
57 | static_assert(!ranges::common_range<const R>); | |
58 | } | |
59 | ||
60 | void | |
61 | test03() | |
62 | { | |
63 | auto v = (views::iota(0,4) | |
64 | | views::transform([] (int i) { return views::iota(0,i); }) | |
65 | | views::filter([] (auto) { return true; }) | |
66 | | views::join); | |
67 | VERIFY( ranges::equal(v, (int[]){0,0,1,0,1,2}) ); | |
68 | using R = decltype(v); | |
69 | static_assert(ranges::input_range<R>); | |
70 | static_assert(!ranges::range<const R>); | |
71 | static_assert(!ranges::forward_range<R>); | |
72 | static_assert(!ranges::common_range<const R>); | |
73 | } | |
74 | ||
75 | void | |
76 | test04() | |
77 | { | |
78 | auto v = (views::iota(0,4) | |
79 | | views::transform([] (int i) { return views::iota(0,i); })); | |
80 | auto v2 = ranges::ref_view{v}; | |
81 | VERIFY( ranges::equal(v2 | views::join, (int[]){0,0,1,0,1,2}) ); | |
82 | using R = decltype(v2); | |
83 | static_assert(ranges::random_access_range<R>); | |
84 | static_assert(ranges::range<const R>); | |
85 | static_assert(ranges::common_range<const R>); | |
86 | static_assert(ranges::random_access_range<ranges::range_reference_t<R>>); | |
87 | static_assert(!std::is_reference_v<ranges::range_reference_t<R>>); | |
88 | } | |
89 | ||
90 | void | |
91 | test05() | |
92 | { | |
93 | using namespace std::literals; | |
94 | std::vector<std::string> x = {"the", " ", "quick", " ", "brown", " ", "fox"}; | |
95 | auto v = x | views::join | views::split(' '); | |
96 | auto i = v.begin(); | |
97 | VERIFY( ranges::equal(*i++, "the"sv) ); | |
98 | VERIFY( ranges::equal(*i++, "quick"sv) ); | |
99 | VERIFY( ranges::equal(*i++, "brown"sv) ); | |
100 | VERIFY( ranges::equal(*i++, "fox"sv) ); | |
101 | VERIFY( i == v.end() ); | |
102 | } | |
103 | ||
104 | int | |
105 | main() | |
106 | { | |
107 | test01(); | |
108 | test02(); | |
109 | test03(); | |
110 | test04(); | |
111 | test05(); | |
112 | } |