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

source code of libcxx/test/std/ranges/range.adaptors/range.all/all_t.compile.pass.cpp