Debian Codegraph @

libstdc++-v3/testsuite/std/ranges/adaptors/counted.cc

raw
1 // Copyright (C) 2020-2025 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-do run { target c++20 } }
19
20 #include <algorithm>
21 #include <ranges>
22 #include <testsuite_hooks.h>
23 #include <testsuite_iterators.h>
24
25 using __gnu_test::test_range;
26 using __gnu_test::forward_iterator_wrapper;
27
28 namespace ranges = std::ranges;
29 namespace views = ranges::views;
30
31 void
32 test01()
33 {
34 int x[] = {0,1,2,3,4,5,0,1,2,3,4,5};
35 auto v = views::counted(x, 5);
36 VERIFY( ranges::equal(v, (int[]){0,1,2,3,4}) );
37 using R = decltype(v);
38 static_assert(ranges::view<R>);
39 static_assert(ranges::sized_range<R>);
40 static_assert(ranges::common_range<R>);
41 static_assert(ranges::random_access_range<R>);
42 }
43
44 void
45 test02()
46 {
47 int x[] = {0,1,2,3,4,5,0,1,2,3,4,5};
48 test_range<int, forward_iterator_wrapper> rx(x);
49 auto v = views::counted(rx.begin(), 5);
50 VERIFY( ranges::equal(v, (int[]){0,1,2,3,4}) );
51 using R = decltype(v);
52 static_assert(ranges::view<R>);
53 static_assert(ranges::sized_range<R>);
54 static_assert(!ranges::common_range<R>);
55 static_assert(!ranges::bidirectional_range<R>);
56 }
57
58 int
59 main()
60 {
61 test01();
62 test02();
63 }