]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/std/ranges/adaptors/all.cc
1 // Copyright (C) 2020-2021 Free Software Foundation, Inc.
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)
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.
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/>.
18 // { dg-options "-std=gnu++2a" }
19 // { dg-do run { target c++2a } }
23 #include <testsuite_hooks.h>
24 #include <testsuite_iterators.h>
26 namespace ranges
= std::ranges
;
27 namespace views
= std::ranges::views
;
32 int x
[] = {1,2,3,4,5};
33 auto v
= views::all(x
);
35 static_assert(ranges::view
<decltype(v
)>);
36 static_assert(ranges::random_access_range
<decltype(v
)>);
38 VERIFY( ranges::size(v
) == 5 );
39 VERIFY( ranges::size(x
| views::all
) == 5 );
40 VERIFY( ranges::size(v
| views::all
| views::all
) == 5 );
41 VERIFY( ranges::size(v
| (views::all
| views::all
)) == 5 );
44 VERIFY( ranges::equal(v
, (int[]){5,4,3,2,1}) );
52 for (auto&& i
: ranges::ref_view
{x
})
54 VERIFY( ranges::equal(x
, (int[]){1,2,3,4,5}) );
60 std::array ints
{0,1,2,3,4,5};
61 auto even
= [] (int i
) { return i
%2==0; };
62 auto odd
= [] (int i
) { return i
%2==1; };
63 auto square
= [] (int i
) { return i
*i
; };
67 | (views::filter(even
)
68 | (views::filter(odd
) | views::all
)))
69 | views::transform(square
)))
77 auto odd
= [] (int i
) { return i
%2==1; };
78 auto square
= [] (int i
) { return i
*i
; };
79 auto increment
= [] (int i
) { return i
+1; };
80 auto small
= [] (int i
) { return i
<30; };
81 auto non_negative
= [] (int i
) { return i
>=0; };
82 auto negative
= [] (int i
) { return i
<0; };
83 return ranges::equal(views::iota(-5)
84 | views::drop_while(negative
)
85 | views::take_while(non_negative
)
86 | views::transform(increment
)
90 | views::transform(square
),
92 | views::drop_while(negative
)
95 | views::transform(square
)
96 | views::take_while(small
)
97 | views::take_while(small
));
100 static_assert(std::is_empty_v
<decltype(views::common
106 static_assert(sizeof(decltype(views::take(5) | views::drop(5)))
107 == sizeof(decltype(views::take(5)
120 static_assert(test03());
121 static_assert(test04());