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