]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/std/ranges/iota/iota_view.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / std / ranges / iota / iota_view.cc
CommitLineData
99dee823 1// Copyright (C) 2019-2021 Free Software Foundation, Inc.
37f33df7
JW
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 <ranges>
22#include <testsuite_hooks.h>
23
24void
25test01()
26{
27 int vals[5] = { };
28 int* out = vals;
29 for (int i : std::ranges::iota_view{1, 4})
30 *out++ = i;
31 VERIFY(out == vals + 3);
32 VERIFY(vals[0] == 1);
33 VERIFY(vals[1] == 2);
34 VERIFY(vals[2] == 3);
35 VERIFY(vals[3] == 0);
36}
37
38void
39test02()
40{
41 auto v = std::ranges::views::iota(4);
42 auto it = v.begin();
43 VERIFY( *it == 4 );
44 ++it;
45 VERIFY( *it == 5 );
46 it++;
47 VERIFY( *it == 6 );
48}
49
50void
51test03()
52{
53 auto v = std::ranges::views::iota(10, 15);
54 auto it = v.begin();
55 VERIFY( *it == 10 );
56 it += 2;
57 VERIFY( *it == 12 );
58 it += 2;
59 VERIFY( *it == 14 );
60 ++it;
61 VERIFY( it == v.end() );
62}
63
5586e506
PP
64void
65test04()
66{
67 int x[] = {1,2,3};
68 auto v = std::ranges::views::iota(std::counted_iterator(x, 3),
69 std::default_sentinel);
70 auto it = v.begin();
71 VERIFY( (*it).base() == x );
72 ++it;
73 VERIFY( (*it).base() == x+1 );
74 ++it;
75 VERIFY( (*it).base() == x+2 );
76 ++it;
77 VERIFY( it == v.end() );
78}
79
62344335
PP
80// Verify we optimize away the 'bound' data member of an unbounded iota_view.
81static_assert(sizeof(std::ranges::iota_view<char>) == 1);
82
37f33df7
JW
83int
84main()
85{
86 test01();
87 test02();
88 test03();
5586e506 89 test04();
37f33df7 90}