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