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 // UNSUPPORTED: libcpp-has-no-incomplete-ranges
11 
12 // template<class R>
13 //   explicit join_view(R&&) -> join_view<views::all_t<R>>;
14 
15 #include <ranges>
16 #include <utility>
17 
18 struct Child {
19   int *begin() const;
20   int *end() const;
21 };
22 
23 struct View : std::ranges::view_base {
24   Child *begin() const;
25   Child *end() const;
26 };
27 
28 struct Range {
29   Child *begin() const;
30   Child *end() const;
31 };
32 
33 struct BorrowedRange {
34   Child *begin() const;
35   Child *end() const;
36 };
37 template<>
38 inline constexpr bool std::ranges::enable_borrowed_range<BorrowedRange> = true;
39 
40 struct NestedChildren : std::ranges::view_base {
41   View* begin() const;
42   View* end() const;
43 };
44 
testCTAD()45 void testCTAD() {
46     View v;
47     Range r;
48     BorrowedRange br;
49 
50     static_assert(std::same_as<
51         decltype(std::ranges::join_view(v)),
52         std::ranges::join_view<View>
53     >);
54     static_assert(std::same_as<
55         decltype(std::ranges::join_view(std::move(v))),
56         std::ranges::join_view<View>
57     >);
58     static_assert(std::same_as<
59         decltype(std::ranges::join_view(r)),
60         std::ranges::join_view<std::ranges::ref_view<Range>>
61     >);
62     static_assert(std::same_as<
63         decltype(std::ranges::join_view(std::move(r))),
64         std::ranges::join_view<std::ranges::owning_view<Range>>
65     >);
66     static_assert(std::same_as<
67         decltype(std::ranges::join_view(br)),
68         std::ranges::join_view<std::ranges::ref_view<BorrowedRange>>
69     >);
70     static_assert(std::same_as<
71         decltype(std::ranges::join_view(std::move(br))),
72         std::ranges::join_view<std::ranges::owning_view<BorrowedRange>>
73     >);
74 
75     NestedChildren n;
76     std::ranges::join_view jv(n);
77 
78     // CTAD generated from the copy constructor instead of joining the join_view
79     static_assert(std::same_as< decltype(std::ranges::join_view(jv)), decltype(jv) >);
80 
81     // CTAD generated from the move constructor instead of joining the join_view
82     static_assert(std::same_as< decltype(std::ranges::join_view(std::move(jv))), decltype(jv) >);
83 }
84