]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/std/ranges/p2259.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / std / ranges / p2259.cc
CommitLineData
83ffe9cd 1// Copyright (C) 2021-2023 Free Software Foundation, Inc.
902b40c7
PP
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 compile { target c++2a } }
20
21// Verify P2259 changes.
22
23#include <ranges>
24#include <tuple>
25#include <vector>
26
27namespace ranges = std::ranges;
28namespace views = std::views;
29
30using std::__detail::__iter_without_category;
31
32template<typename _Range>
33concept only_cxx20_input_range = ranges::input_range<_Range>
34 && !ranges::forward_range<_Range>
35 && __iter_without_category<ranges::iterator_t<_Range>>;
36
37void
38test01()
39{
40 extern std::vector<int> vec;
41 only_cxx20_input_range auto v0
42 = vec
43 | views::transform([](int c) { return views::single(c); })
44 | views::join;
45
46 // Verify the changes to filter_view.
47 only_cxx20_input_range auto v1 = v0 | views::filter([](int c) { return c > 0; });
48
49 // Verify the changes to transform_view.
50 only_cxx20_input_range auto v2 = v0 | views::transform([](int& c) -> auto& { return c; });
51
adbd2c71
PP
52 // Verify the changes to lazy_split_view.
53 only_cxx20_input_range auto v3 = v0 | views::lazy_split(12);
902b40c7
PP
54 static_assert(only_cxx20_input_range<decltype(*v3.begin())>);
55
56 // Verify the changes to join_view.
adbd2c71 57 only_cxx20_input_range auto v4 = v0 | views::lazy_split(12) | views::join;
902b40c7
PP
58
59 // Verify the changes to elements_view.
60 only_cxx20_input_range auto v5
61 = v0
62 | views::transform([](int c) { return std::make_tuple(c, c); })
63 | views::elements<0>;
64
65 // Verify the changes to common_iterator.
66 only_cxx20_input_range auto v6 = v0 | views::common;
240b01b0 67 (void) *(v6.begin()++);
902b40c7
PP
68
69 // Verify the changes to iota_view.
70 only_cxx20_input_range auto v8 = ranges::iota_view{v0.begin()};
71
72 // Verify the changes to move_iterator.
73 __iter_without_category auto i9 = std::make_move_iterator(v0.begin());
74
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>);
240b01b0 80 (void) i10.operator->();
902b40c7
PP
81 __iter_without_category auto i11 = std::counted_iterator{v0.begin(), 5};
82}
83
84void
85test02()
86{
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)>);
91}