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-options "-std=gnu++2a" }
19 // { dg-do compile { target c++2a } }
21 // Verify P2259 changes.
27 namespace ranges
= std::ranges
;
28 namespace views
= std::views
;
30 using std::__detail::__iter_without_category
;
32 template<typename _Range
>
33 concept only_cxx20_input_range
= ranges::input_range
<_Range
>
34 && !ranges::forward_range
<_Range
>
35 && __iter_without_category
<ranges::iterator_t
<_Range
>>;
40 extern std::vector
<int> vec
;
41 only_cxx20_input_range
auto v0
43 | views::transform([](int c
) { return views::single(c
); })
46 // Verify the changes to filter_view.
47 only_cxx20_input_range
auto v1
= v0
| views::filter([](int c
) { return c
> 0; });
49 // Verify the changes to transform_view.
50 only_cxx20_input_range
auto v2
= v0
| views::transform([](int& c
) -> auto& { return c
; });
52 // Verify the changes to lazy_split_view.
53 only_cxx20_input_range
auto v3
= v0
| views::lazy_split(12);
54 static_assert(only_cxx20_input_range
<decltype(*v3
.begin())>);
56 // Verify the changes to join_view.
57 only_cxx20_input_range
auto v4
= v0
| views::lazy_split(12) | views::join
;
59 // Verify the changes to elements_view.
60 only_cxx20_input_range
auto v5
62 | views::transform([](int c
) { return std::make_tuple(c
, c
); })
65 // Verify the changes to common_iterator.
66 only_cxx20_input_range
auto v6
= v0
| views::common
;
67 (void) *(v6
.begin()++);
69 // Verify the changes to iota_view.
70 only_cxx20_input_range
auto v8
= ranges::iota_view
{v0
.begin()};
72 // Verify the changes to move_iterator.
73 __iter_without_category
auto i9
= std::make_move_iterator(v0
.begin());
75 // Verify the changes to counted_iterator.
76 extern std::counted_iterator
<int*> i10
;
77 static_assert(std::contiguous_iterator
<decltype(i10
)>);
78 static_assert(std::same_as
<std::iterator_traits
<decltype(i10
)>::iterator_category
,
79 std::random_access_iterator_tag
>);
80 (void) i10
.operator->();
81 __iter_without_category
auto i11
= std::counted_iterator
{v0
.begin(), 5};
87 // Verify LWG 3291 example.
88 auto v
= views::iota(0);
89 auto i
= std::counted_iterator
{v
.begin(), 5};
90 static_assert(std::random_access_iterator
<decltype(i
)>);