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