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 // [customization.point.object]
13 // [range.adaptor.object] "A range adaptor object is a customization point object..."
14
15 #include <compare>
16 #include <concepts>
17 #include <iterator>
18 #include <ranges>
19 #include <type_traits>
20 #include <utility>
21
22 // Test for basic properties of C++20 16.3.3.3.6 [customization.point.object].
23 template <class CPO, class... Args>
test(CPO & o,Args &&...)24 constexpr bool test(CPO& o, Args&&...) {
25 static_assert(std::is_const_v<CPO>);
26 static_assert(std::is_class_v<CPO>);
27 static_assert(std::is_trivial_v<CPO>);
28
29 auto p = o;
30 using T = decltype(p);
31
32 // The type of a customization point object, ignoring cv-qualifiers, shall model semiregular.
33 static_assert(std::semiregular<T>);
34
35 // The type T of a customization point object, ignoring cv-qualifiers, shall model...
36 static_assert(std::invocable<T&, Args...>);
37 static_assert(std::invocable<const T&, Args...>);
38 static_assert(std::invocable<T, Args...>);
39 static_assert(std::invocable<const T, Args...>);
40
41 return true;
42 }
43
44 int a[10];
45 int arrays[10][10];
46 //std::pair<int, int> pairs[10];
47
48 // [concept.swappable]
49 static_assert(test(std::ranges::swap, a, a));
50
51 // [iterator.cust]
52 static_assert(test(std::ranges::iter_move, a + 0));
53 static_assert(test(std::ranges::iter_swap, a + 0, a + 1));
54
55 // [cmp.alg]
56 static_assert(test(std::partial_order, 1, 2));
57 static_assert(test(std::strong_order, 1, 2));
58 static_assert(test(std::weak_order, 1, 2));
59 static_assert(test(std::compare_partial_order_fallback, 1, 2));
60 static_assert(test(std::compare_strong_order_fallback, 1, 2));
61 static_assert(test(std::compare_weak_order_fallback, 1, 2));
62
63 // [range.access]
64 static_assert(test(std::ranges::begin, a));
65 static_assert(test(std::ranges::end, a));
66 static_assert(test(std::ranges::cbegin, a));
67 static_assert(test(std::ranges::cdata, a));
68 static_assert(test(std::ranges::cend, a));
69 static_assert(test(std::ranges::crbegin, a));
70 static_assert(test(std::ranges::crend, a));
71 static_assert(test(std::ranges::data, a));
72 static_assert(test(std::ranges::empty, a));
73 static_assert(test(std::ranges::rbegin, a));
74 static_assert(test(std::ranges::rend, a));
75 static_assert(test(std::ranges::size, a));
76 static_assert(test(std::ranges::ssize, a));
77
78 // [range.factories]
79 // views::empty<T> is not a CPO
80 static_assert(test(std::views::iota, 1));
81 static_assert(test(std::views::iota, 1, 10));
82 //static_assert(test(std::views::istream<int>, 1);
83 static_assert(test(std::views::single, 4));
84
85 // [range.adaptors]
86 static_assert(test(std::views::all, a));
87 static_assert(test(std::views::common, a));
88 static_assert(test(std::views::counted, a, 10));
89 static_assert(test(std::views::drop, a, 10));
90 //static_assert(test(std::views::drop_while, a, [](int x){ return x < 10; }));
91 //static_assert(test(std::views::elements<0>, pairs));
__anonb4ddb2910102(int x)92 static_assert(test(std::views::filter, a, [](int x){ return x < 10; }));
93 static_assert(test(std::views::join, arrays));
94 //static_assert(test(std::views::split, a, 4));
95 static_assert(test(std::views::lazy_split, a, 4));
96 static_assert(test(std::views::reverse, a));
97 static_assert(test(std::views::take, a, 10));
98 //static_assert(test(std::views::take_while, a, [](int x){ return x < 10; }));
__anonb4ddb2910202(int x)99 static_assert(test(std::views::transform, a, [](int x){ return x + 1; }));
100