1 // Copyright (C) 2021-2023 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-do compile { target c++20 } }
20 // Verify P2259 changes.
26 namespace ranges
= std::ranges
;
27 namespace views
= std::views
;
29 using std::__detail::__iter_without_category
;
31 template<typename _Range
>
32 concept only_cxx20_input_range
= ranges::input_range
<_Range
>
33 && !ranges::forward_range
<_Range
>
34 && __iter_without_category
<ranges::iterator_t
<_Range
>>;
39 extern std::vector
<int> vec
;
40 only_cxx20_input_range
auto v0
42 | views::transform([](int c
) { return views::single(c
); })
45 // Verify the changes to filter_view.
46 only_cxx20_input_range
auto v1
= v0
| views::filter([](int c
) { return c
> 0; });
48 // Verify the changes to transform_view.
49 only_cxx20_input_range
auto v2
= v0
| views::transform([](int& c
) -> auto& { return c
; });
51 // Verify the changes to lazy_split_view.
52 only_cxx20_input_range
auto v3
= v0
| views::lazy_split(12);
53 static_assert(only_cxx20_input_range
<decltype(*v3
.begin())>);
55 // Verify the changes to join_view.
56 only_cxx20_input_range
auto v4
= v0
| views::lazy_split(12) | views::join
;
58 // Verify the changes to elements_view.
59 only_cxx20_input_range
auto v5
61 | views::transform([](int c
) { return std::make_tuple(c
, c
); })
64 // Verify the changes to common_iterator.
65 only_cxx20_input_range
auto v6
= v0
| views::common
;
66 (void) *(v6
.begin()++);
68 // Verify the changes to iota_view.
69 only_cxx20_input_range
auto v8
= ranges::iota_view
{v0
.begin()};
71 // Verify the changes to move_iterator.
72 __iter_without_category
auto i9
= std::make_move_iterator(v0
.begin());
74 // Verify the changes to counted_iterator.
75 extern std::counted_iterator
<int*> i10
;
76 static_assert(std::contiguous_iterator
<decltype(i10
)>);
77 static_assert(std::same_as
<std::iterator_traits
<decltype(i10
)>::iterator_category
,
78 std::random_access_iterator_tag
>);
79 (void) i10
.operator->();
80 __iter_without_category
auto i11
= std::counted_iterator
{v0
.begin(), 5};
86 // Verify LWG 3291 example.
87 auto v
= views::iota(0);
88 auto i
= std::counted_iterator
{v
.begin(), 5};
89 static_assert(std::random_access_iterator
<decltype(i
)>);