]>
Commit | Line | Data |
---|---|---|
a25321ca PP |
1 | // Copyright (C) 2021 Free Software Foundation, Inc. |
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 | ||
27 | namespace ranges = std::ranges; | |
28 | namespace views = std::ranges::views; | |
29 | ||
30 | // Verify P2281 changes to the forwarding semantics of partial application | |
31 | // and composition of range adaptor objects. | |
32 | ||
33 | void | |
34 | test01() | |
35 | { | |
36 | auto split_into_strings = [] (auto p) { | |
37 | return views::split(p) | views::transform([](auto r){ | |
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 | ||
49 | struct 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 | ||
60 | template<> | |
61 | inline constexpr bool std::ranges::enable_view<move_only_range> = true; | |
62 | ||
63 | template<auto split = views::split> | |
64 | void | |
65 | test02() | |
66 | { | |
67 | std::string_view s; | |
68 | move_only_range p; | |
69 | static_assert(requires { s | split(std::move(p)); }); | |
70 | static_assert(requires { split(std::move(p))(s); }); | |
71 | static_assert(requires { split(std::move(p)) | views::all; }); | |
72 | static_assert(requires { views::all | split(std::move(p)); }); | |
73 | static_assert(!requires { split(p); }); | |
74 | static_assert(!requires { split(p) | views::all; }); | |
75 | static_assert(!requires { views::all | split(p); }); | |
76 | } | |
77 | ||
78 | int | |
79 | main() | |
80 | { | |
81 | test01(); | |
82 | test02(); | |
83 | } |