]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/std/ranges/iota/iota_view.cc
1 // Copyright (C) 2019-2022 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>
30 for (int i
: std::ranges::iota_view
{1, 4})
32 VERIFY(out
== vals
+ 3);
42 auto v
= std::ranges::views::iota(4);
54 auto v
= std::ranges::views::iota(10, 15);
62 VERIFY( it
== v
.end() );
69 auto v
= std::ranges::views::iota(std::counted_iterator(x
, 3),
70 std::default_sentinel
);
72 VERIFY( (*it
).base() == x
);
74 VERIFY( (*it
).base() == x
+1 );
76 VERIFY( (*it
).base() == x
+2 );
78 VERIFY( it
== v
.end() );
81 // Verify we optimize away the 'bound' data member of an unbounded iota_view.
82 static_assert(sizeof(std::ranges::iota_view
<char>) == 1);
87 // PR libstdc++/100690
88 int x
[] = {42, 42, 42};
89 auto r
= std::views::iota(std::ranges::begin(x
), std::ranges::cbegin(x
) + 3);
90 VERIFY( r
.end() - r
.begin() == 3 );
91 VERIFY( r
.begin() - r
.end() == -3 );
97 // Verify LWG 3523 changes.
98 auto v1
= std::views::iota(0, 5);
99 auto w1
= decltype(v1
)(v1
.begin(), v1
.end());
100 VERIFY( std::ranges::equal(v1
, w1
) );
102 auto v2
= std::views::iota(0);
103 auto w2
= decltype(v2
)(v2
.begin(), v2
.end());
104 static_assert(std::same_as
<decltype(w2
.end()), std::unreachable_sentinel_t
>);
105 VERIFY( *w2
.begin() == 0 );
107 auto v3
= std::views::iota(0, 5l);
108 auto w3
= decltype(v3
)(v3
.begin(), v3
.end());
109 static_assert(!std::ranges::common_range
<decltype(w3
)>);
110 VERIFY( std::ranges::equal(v3
, w3
) );