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].
22template <class CPO, class... Args>
23constexpr 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_trivially_copyable_v<CPO>);
27 static_assert(std::is_trivially_default_constructible_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
44int a[10];
45int arrays[10][10];
46//std::pair<int, int> pairs[10];
47
48// [concept.swappable]
49static_assert(test(std::ranges::swap, a, a));
50
51// [iterator.cust]
52static_assert(test(std::ranges::iter_move, a + 0));
53static_assert(test(std::ranges::iter_swap, a + 0, a + 1));
54
55// [cmp.alg]
56static_assert(test(std::partial_order, 1, 2));
57static_assert(test(std::strong_order, 1, 2));
58static_assert(test(std::weak_order, 1, 2));
59static_assert(test(std::compare_partial_order_fallback, 1, 2));
60static_assert(test(std::compare_strong_order_fallback, 1, 2));
61static_assert(test(std::compare_weak_order_fallback, 1, 2));
62
63// [range.access]
64static_assert(test(std::ranges::begin, a));
65static_assert(test(std::ranges::end, a));
66static_assert(test(std::ranges::cbegin, a));
67static_assert(test(std::ranges::cdata, a));
68static_assert(test(std::ranges::cend, a));
69static_assert(test(std::ranges::crbegin, a));
70static_assert(test(std::ranges::crend, a));
71static_assert(test(std::ranges::data, a));
72static_assert(test(std::ranges::empty, a));
73static_assert(test(std::ranges::rbegin, a));
74static_assert(test(std::ranges::rend, a));
75static_assert(test(std::ranges::size, a));
76static_assert(test(std::ranges::ssize, a));
77
78// [range.factories]
79// views::empty<T> is not a CPO
80static_assert(test(std::views::iota, 1));
81static_assert(test(std::views::iota, 1, 10));
82//static_assert(test(std::views::istream<int>, 1);
83static_assert(test(std::views::single, 4));
84
85// [range.adaptors]
86static_assert(test(std::views::all, a));
87static_assert(test(std::views::common, a));
88static_assert(test(std::views::counted, a, 10));
89static_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));
92static_assert(test(std::views::filter, a, [](int x){ return x < 10; }));
93static_assert(test(std::views::join, arrays));
94//static_assert(test(std::views::split, a, 4));
95static_assert(test(std::views::lazy_split, a, 4));
96static_assert(test(std::views::reverse, a));
97static_assert(test(std::views::take, a, 10));
98//static_assert(test(std::views::take_while, a, [](int x){ return x < 10; }));
99static_assert(test(std::views::transform, a, [](int x){ return x + 1; }));
100

source code of libcxx/test/std/library/description/conventions/customization.point.object/cpo.compile.pass.cpp