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> |
12 | // common_view(R&&) -> common_view<views::all_t<R>>; |
13 | |
14 | #include <ranges> |
15 | #include <cassert> |
16 | |
17 | #include "test_iterators.h" |
18 | |
19 | struct View : std::ranges::view_base { |
20 | int *begin() const; |
21 | sentinel_wrapper<int*> end() const; |
22 | }; |
23 | |
24 | struct Range { |
25 | int *begin() const; |
26 | sentinel_wrapper<int*> end() const; |
27 | }; |
28 | |
29 | struct BorrowedRange { |
30 | int *begin() const; |
31 | sentinel_wrapper<int*> end() const; |
32 | }; |
33 | template<> |
34 | inline constexpr bool std::ranges::enable_borrowed_range<BorrowedRange> = true; |
35 | |
36 | void testCTAD() { |
37 | View v; |
38 | Range r; |
39 | BorrowedRange br; |
40 | |
41 | static_assert(std::same_as< |
42 | decltype(std::ranges::common_view(v)), |
43 | std::ranges::common_view<View> |
44 | >); |
45 | static_assert(std::same_as< |
46 | decltype(std::ranges::common_view(std::move(v))), |
47 | std::ranges::common_view<View> |
48 | >); |
49 | static_assert(std::same_as< |
50 | decltype(std::ranges::common_view(r)), |
51 | std::ranges::common_view<std::ranges::ref_view<Range>> |
52 | >); |
53 | static_assert(std::same_as< |
54 | decltype(std::ranges::common_view(std::move(r))), |
55 | std::ranges::common_view<std::ranges::owning_view<Range>> |
56 | >); |
57 | static_assert(std::same_as< |
58 | decltype(std::ranges::common_view(br)), |
59 | std::ranges::common_view<std::ranges::ref_view<BorrowedRange>> |
60 | >); |
61 | static_assert(std::same_as< |
62 | decltype(std::ranges::common_view(std::move(br))), |
63 | std::ranges::common_view<std::ranges::owning_view<BorrowedRange>> |
64 | >); |
65 | } |
66 | |