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