1 | //===----------------------------------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | // UNSUPPORTED: c++03, c++11, c++14, c++17 |
10 | |
11 | // template<class R, class F> |
12 | // transform_view(R&&, F) -> transform_view<views::all_t<R>, F>; |
13 | |
14 | #include <cassert> |
15 | #include <concepts> |
16 | #include <ranges> |
17 | #include <utility> |
18 | |
19 | struct PlusOne { |
20 | int operator()(int x) const; |
21 | }; |
22 | |
23 | struct View : std::ranges::view_base { |
24 | int *begin() const; |
25 | int *end() const; |
26 | }; |
27 | |
28 | struct Range { |
29 | int *begin() const; |
30 | int *end() const; |
31 | }; |
32 | |
33 | struct BorrowedRange { |
34 | int *begin() const; |
35 | int *end() const; |
36 | }; |
37 | template<> |
38 | inline constexpr bool std::ranges::enable_borrowed_range<BorrowedRange> = true; |
39 | |
40 | void testCTAD() { |
41 | View v; |
42 | Range r; |
43 | BorrowedRange br; |
44 | PlusOne f; |
45 | |
46 | static_assert(std::same_as< |
47 | decltype(std::ranges::transform_view(v, f)), |
48 | std::ranges::transform_view<View, PlusOne> |
49 | >); |
50 | static_assert(std::same_as< |
51 | decltype(std::ranges::transform_view(std::move(v), f)), |
52 | std::ranges::transform_view<View, PlusOne> |
53 | >); |
54 | static_assert(std::same_as< |
55 | decltype(std::ranges::transform_view(r, f)), |
56 | std::ranges::transform_view<std::ranges::ref_view<Range>, PlusOne> |
57 | >); |
58 | static_assert(std::same_as< |
59 | decltype(std::ranges::transform_view(std::move(r), f)), |
60 | std::ranges::transform_view<std::ranges::owning_view<Range>, PlusOne> |
61 | >); |
62 | static_assert(std::same_as< |
63 | decltype(std::ranges::transform_view(br, f)), |
64 | std::ranges::transform_view<std::ranges::ref_view<BorrowedRange>, PlusOne> |
65 | >); |
66 | static_assert(std::same_as< |
67 | decltype(std::ranges::transform_view(std::move(br), f)), |
68 | std::ranges::transform_view<std::ranges::owning_view<BorrowedRange>, PlusOne> |
69 | >); |
70 | } |
71 | |