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<viewable_range R> |
12 | // using all_t = decltype(views::all(declval<R>())); |
13 | |
14 | #include <ranges> |
15 | |
16 | #include "test_iterators.h" |
17 | |
18 | struct View : std::ranges::view_base { |
19 | int *begin() const; |
20 | int *end() const; |
21 | }; |
22 | |
23 | struct Range { |
24 | int *begin() const; |
25 | int *end() const; |
26 | }; |
27 | |
28 | struct BorrowableRange { |
29 | int *begin() const; |
30 | int *end() const; |
31 | }; |
32 | template<> |
33 | inline constexpr bool std::ranges::enable_borrowed_range<BorrowableRange> = true; |
34 | |
35 | template <class T> |
36 | concept HasAllT = requires { |
37 | typename std::views::all_t<T>; |
38 | }; |
39 | |
40 | // When T is a view, returns decay-copy(T) |
41 | ASSERT_SAME_TYPE(std::views::all_t<View>, View); |
42 | ASSERT_SAME_TYPE(std::views::all_t<View&>, View); |
43 | ASSERT_SAME_TYPE(std::views::all_t<View&&>, View); |
44 | ASSERT_SAME_TYPE(std::views::all_t<const View>, View); |
45 | ASSERT_SAME_TYPE(std::views::all_t<const View&>, View); |
46 | ASSERT_SAME_TYPE(std::views::all_t<const View&&>, View); |
47 | |
48 | // Otherwise, when T is a reference to a range, returns ref_view<T> |
49 | ASSERT_SAME_TYPE(std::views::all_t<Range&>, std::ranges::ref_view<Range>); |
50 | ASSERT_SAME_TYPE(std::views::all_t<const Range&>, std::ranges::ref_view<const Range>); |
51 | ASSERT_SAME_TYPE(std::views::all_t<BorrowableRange&>, std::ranges::ref_view<BorrowableRange>); |
52 | ASSERT_SAME_TYPE(std::views::all_t<const BorrowableRange&>, std::ranges::ref_view<const BorrowableRange>); |
53 | |
54 | // Otherwise, returns owning_view<T> |
55 | ASSERT_SAME_TYPE(std::views::all_t<Range>, std::ranges::owning_view<Range>); |
56 | ASSERT_SAME_TYPE(std::views::all_t<Range&&>, std::ranges::owning_view<Range>); |
57 | static_assert(!HasAllT<const Range>); |
58 | static_assert(!HasAllT<const Range&&>); |
59 | ASSERT_SAME_TYPE(std::views::all_t<BorrowableRange>, std::ranges::owning_view<BorrowableRange>); |
60 | ASSERT_SAME_TYPE(std::views::all_t<BorrowableRange&&>, std::ranges::owning_view<BorrowableRange>); |
61 | static_assert(!HasAllT<const BorrowableRange>); |
62 | static_assert(!HasAllT<const BorrowableRange&&>); |
63 | |