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// REQUIRES: stdlib=libc++
11
12// [algorithms.requirements]/2
13// [range.iter.ops.general]/2
14
15#include <algorithm>
16#include <concepts>
17#include <iterator>
18#include <memory>
19#include <random>
20#include <ranges>
21#include <type_traits>
22#include <utility>
23#include "test_macros.h"
24
25// Niebloids, unlike CPOs, are *not* required to be semiregular or even to have
26// a declared type at all; they are specified as "magic" overload sets whose
27// names are not found by argument-dependent lookup and which inhibit
28// argument-dependent lookup if they are found via a `using`-declaration.
29//
30// libc++ implements them using the same function-object technique we use for CPOs;
31// therefore this file should stay in sync with ./cpo.compile.pass.cpp.
32
33template <class CPO, class... Args>
34constexpr bool test(CPO& o, Args&&...) {
35 static_assert(std::is_const_v<CPO>);
36 static_assert(std::is_class_v<CPO>);
37 static_assert(std::is_trivial_v<CPO>);
38
39 auto p = o;
40 using T = decltype(p);
41
42 // The type of a customization point object, ignoring cv-qualifiers, shall model semiregular.
43 static_assert(std::semiregular<T>);
44
45 // The type T of a customization point object, ignoring cv-qualifiers, shall model...
46 static_assert(std::invocable<T&, Args...>);
47 static_assert(std::invocable<const T&, Args...>);
48 static_assert(std::invocable<T, Args...>);
49 static_assert(std::invocable<const T, Args...>);
50
51 return true;
52}
53
54int *p;
55int a[10];
56auto odd = [](int x) { return x % 2 != 0; };
57auto triple = [](int x) { return 3*x; };
58auto gen = [] { return 42; };
59std::mt19937 g;
60
61// [algorithm.syn]
62
63static_assert(test(std::ranges::adjacent_find, a));
64static_assert(test(std::ranges::all_of, a, odd));
65static_assert(test(std::ranges::any_of, a, odd));
66static_assert(test(std::ranges::binary_search, a, 42));
67static_assert(test(std::ranges::clamp, 42, 42, 42));
68#if TEST_STD_VER >= 23
69static_assert(test(std::ranges::contains, a, 42));
70static_assert(test(std::ranges::contains_subrange, a, a));
71#endif
72static_assert(test(std::ranges::copy, a, a));
73static_assert(test(std::ranges::copy_backward, a, a));
74static_assert(test(std::ranges::copy_if, a, a, odd));
75static_assert(test(std::ranges::copy_n, a, 10, a));
76static_assert(test(std::ranges::count, a, 42));
77static_assert(test(std::ranges::count_if, a, odd));
78#if TEST_STD_VER >= 23
79static_assert(test(std::ranges::ends_with, a, a));
80#endif
81static_assert(test(std::ranges::equal, a, a));
82static_assert(test(std::ranges::equal_range, a, 42));
83static_assert(test(std::ranges::fill, a, 42));
84static_assert(test(std::ranges::fill_n, a, 10, 42));
85static_assert(test(std::ranges::find, a, 42));
86static_assert(test(std::ranges::find_end, a, a));
87static_assert(test(std::ranges::find_first_of, a, a));
88static_assert(test(std::ranges::find_if, a, odd));
89static_assert(test(std::ranges::find_if_not, a, odd));
90#if TEST_STD_VER >= 23
91static_assert(test(std::ranges::fold_left, a, 0, std::plus()));
92static_assert(test(std::ranges::fold_left_with_iter, a, 0, std::plus()));
93#endif
94static_assert(test(std::ranges::for_each, a, odd));
95static_assert(test(std::ranges::for_each_n, a, 10, odd));
96static_assert(test(std::ranges::generate, a, gen));
97static_assert(test(std::ranges::generate_n, a, 10, gen));
98static_assert(test(std::ranges::includes, a, a));
99static_assert(test(std::ranges::inplace_merge, a, a+5));
100static_assert(test(std::ranges::is_heap, a));
101static_assert(test(std::ranges::is_heap_until, a));
102static_assert(test(std::ranges::is_partitioned, a, odd));
103static_assert(test(std::ranges::is_permutation, a, a));
104static_assert(test(std::ranges::is_sorted, a));
105static_assert(test(std::ranges::is_sorted_until, a));
106static_assert(test(std::ranges::lexicographical_compare, a, a));
107static_assert(test(std::ranges::lower_bound, a, 42));
108static_assert(test(std::ranges::make_heap, a));
109static_assert(test(std::ranges::max, a));
110static_assert(test(std::ranges::max_element, a));
111static_assert(test(std::ranges::merge, a, a, a));
112static_assert(test(std::ranges::min, a));
113static_assert(test(std::ranges::min_element, a));
114static_assert(test(std::ranges::minmax, a));
115static_assert(test(std::ranges::minmax_element, a));
116static_assert(test(std::ranges::mismatch, a, a));
117static_assert(test(std::ranges::move, a, a));
118static_assert(test(std::ranges::move_backward, a, a));
119static_assert(test(std::ranges::next_permutation, a));
120static_assert(test(std::ranges::none_of, a, odd));
121static_assert(test(std::ranges::nth_element, a, a+5));
122static_assert(test(std::ranges::partial_sort, a, a+5));
123static_assert(test(std::ranges::partial_sort_copy, a, a));
124static_assert(test(std::ranges::partition, a, odd));
125static_assert(test(std::ranges::partition_copy, a, a, a, odd));
126static_assert(test(std::ranges::partition_point, a, odd));
127static_assert(test(std::ranges::pop_heap, a));
128static_assert(test(std::ranges::prev_permutation, a));
129static_assert(test(std::ranges::push_heap, a));
130static_assert(test(std::ranges::remove, a, 42));
131static_assert(test(std::ranges::remove_copy, a, a, 42));
132static_assert(test(std::ranges::remove_copy_if, a, a, odd));
133static_assert(test(std::ranges::remove_if, a, odd));
134static_assert(test(std::ranges::replace, a, 42, 43));
135static_assert(test(std::ranges::replace_copy, a, a, 42, 43));
136static_assert(test(std::ranges::replace_copy_if, a, a, odd, 43));
137static_assert(test(std::ranges::replace_if, a, odd, 43));
138static_assert(test(std::ranges::reverse, a));
139static_assert(test(std::ranges::reverse_copy, a, a));
140static_assert(test(std::ranges::rotate, a, a+5));
141static_assert(test(std::ranges::rotate_copy, a, a+5, a));
142static_assert(test(std::ranges::sample, a, a, 5, g));
143static_assert(test(std::ranges::search, a, a));
144static_assert(test(std::ranges::search_n, a, 10, 42));
145static_assert(test(std::ranges::set_difference, a, a, a));
146static_assert(test(std::ranges::set_intersection, a, a, a));
147static_assert(test(std::ranges::set_symmetric_difference, a, a, a));
148static_assert(test(std::ranges::set_union, a, a, a));
149static_assert(test(std::ranges::shuffle, a, g));
150static_assert(test(std::ranges::sort, a));
151static_assert(test(std::ranges::sort_heap, a));
152static_assert(test(std::ranges::stable_partition, a, odd));
153static_assert(test(std::ranges::stable_sort, a));
154#if TEST_STD_VER > 20
155static_assert(test(std::ranges::starts_with, a, a));
156#endif
157static_assert(test(std::ranges::swap_ranges, a, a));
158static_assert(test(std::ranges::transform, a, a, triple));
159static_assert(test(std::ranges::unique, a));
160static_assert(test(std::ranges::unique_copy, a, a));
161static_assert(test(std::ranges::upper_bound, a, 42));
162
163// [memory.syn]
164
165static_assert(test(std::ranges::construct_at, a, 42));
166static_assert(test(std::ranges::destroy, a));
167static_assert(test(std::ranges::destroy, a, a+10));
168static_assert(test(std::ranges::destroy_at, a));
169static_assert(test(std::ranges::destroy_n, a, 10));
170static_assert(test(std::ranges::uninitialized_copy, a, a));
171static_assert(test(std::ranges::uninitialized_copy, a, a+10, a, a+10));
172static_assert(test(std::ranges::uninitialized_copy_n, a, 10, a, a+10));
173static_assert(test(std::ranges::uninitialized_default_construct, a));
174static_assert(test(std::ranges::uninitialized_default_construct, a, a+10));
175static_assert(test(std::ranges::uninitialized_default_construct_n, a, 10));
176static_assert(test(std::ranges::uninitialized_fill, a, 42));
177static_assert(test(std::ranges::uninitialized_fill, a, a+10, 42));
178static_assert(test(std::ranges::uninitialized_fill_n, a, 10, 42));
179static_assert(test(std::ranges::uninitialized_move, a, a));
180static_assert(test(std::ranges::uninitialized_move, a, a+10, a, a+10));
181static_assert(test(std::ranges::uninitialized_move_n, a, 10, a, a+10));
182static_assert(test(std::ranges::uninitialized_value_construct, a));
183static_assert(test(std::ranges::uninitialized_value_construct, a, a+10));
184static_assert(test(std::ranges::uninitialized_value_construct_n, a, 10));
185
186// [numeric.ops.overview] currently has no ranges algorithms. See P1813, P2214
187
188// [range.iter.ops]
189
190static_assert(test(std::ranges::advance, p, 5));
191static_assert(test(std::ranges::advance, p, 5, a+10));
192static_assert(test(std::ranges::advance, p, a+10));
193static_assert(test(std::ranges::distance, a));
194static_assert(test(std::ranges::distance, a, a+10));
195static_assert(test(std::ranges::next, a));
196static_assert(test(std::ranges::next, a, 5));
197static_assert(test(std::ranges::next, a, 5, a+10));
198static_assert(test(std::ranges::next, a, a+10));
199static_assert(test(std::ranges::prev, a+10));
200static_assert(test(std::ranges::prev, a+10, 5));
201static_assert(test(std::ranges::prev, a+10, 5, a));
202

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