]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/std/ranges/adaptors/p2281.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / std / ranges / adaptors / p2281.cc
CommitLineData
7adcbafe 1// Copyright (C) 2021-2022 Free Software Foundation, Inc.
a25321ca
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 run { target c++2a } }
20
21#include <algorithm>
22#include <ranges>
23#include <string>
24#include <string_view>
25#include <testsuite_hooks.h>
26
27namespace ranges = std::ranges;
28namespace views = std::ranges::views;
29
30// Verify P2281 changes to the forwarding semantics of partial application
31// and composition of range adaptor objects.
32
33void
34test01()
35{
36 auto split_into_strings = [] (auto p) {
adbd2c71 37 return views::lazy_split(p) | views::transform([](auto r){
a25321ca
PP
38 return std::string(r.begin(), ranges::next(r.begin(), r.end()));
39 });
40 };
41 constexpr std::string_view s = "hello world";
42 constexpr std::string_view p = " ";
43 constexpr auto v1 = s | split_into_strings(p);
44 constexpr auto v2 = split_into_strings(p)(s);
45 VERIFY( ranges::equal(v1, (std::string_view[]){"hello", "world"}) );
46 VERIFY( ranges::equal(v2, (std::string_view[]){"hello", "world"}) );
47}
48
49struct move_only_range
50{
51 move_only_range() { }
52 move_only_range(move_only_range&&);
53 move_only_range& operator=(move_only_range&&);
54 move_only_range(const move_only_range&) = delete;
55 move_only_range& operator=(const move_only_range&) = delete;
56 char* begin();
57 char* end();
58};
59
60template<>
61 inline constexpr bool std::ranges::enable_view<move_only_range> = true;
62
adbd2c71 63template<auto lazy_split = views::lazy_split>
a25321ca
PP
64void
65test02()
66{
67 std::string_view s;
68 move_only_range p;
adbd2c71
PP
69 static_assert(requires { s | lazy_split(std::move(p)); });
70 static_assert(requires { lazy_split(std::move(p))(s); });
71 static_assert(requires { lazy_split(std::move(p)) | views::all; });
72 static_assert(requires { views::all | lazy_split(std::move(p)); });
73 static_assert(!requires { lazy_split(p); });
74 static_assert(!requires { lazy_split(p) | views::all; });
75 static_assert(!requires { views::all | lazy_split(p); });
a25321ca
PP
76}
77
78int
79main()
80{
81 test01();
82 test02();
83}