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 | // <algorithm> |
10 | |
11 | // template<InputIterator Iter1, InputIterator Iter2, typename Compare> |
12 | // requires Predicate<Compare, Iter1::value_type, Iter2::value_type> |
13 | // && Predicate<Compare, Iter2::value_type, Iter1::value_type> |
14 | // constexpr bool // constexpr after C++17 |
15 | // includes(Iter1 first1, Iter1 last1, Iter2 first2, Iter2 last2, Compare comp); |
16 | |
17 | #include <algorithm> |
18 | #include <functional> |
19 | #include <cassert> |
20 | |
21 | #include "test_macros.h" |
22 | #include "test_iterators.h" |
23 | |
24 | template <class Iter1, class Iter2> |
25 | TEST_CONSTEXPR_CXX20 |
26 | void test() |
27 | { |
28 | int ia[] = {4, 4, 4, 4, 3, 3, 3, 2, 2, 1}; |
29 | const unsigned sa = sizeof(ia)/sizeof(ia[0]); |
30 | int ib[] = {4, 2}; |
31 | const unsigned sb = sizeof(ib)/sizeof(ib[0]); |
32 | int ic[] = {2, 1}; |
33 | const unsigned sc = sizeof(ic)/sizeof(ic[0]); ((void)sc); |
34 | int id[] = {3, 3, 3, 3}; |
35 | const unsigned sd = sizeof(id)/sizeof(id[0]); ((void)sd); |
36 | |
37 | assert(std::includes(Iter1(ia), Iter1(ia), Iter2(ib), Iter2(ib), std::greater<int>())); |
38 | assert(!std::includes(Iter1(ia), Iter1(ia), Iter2(ib), Iter2(ib+1), std::greater<int>())); |
39 | assert(std::includes(Iter1(ia), Iter1(ia+1), Iter2(ib), Iter2(ib), std::greater<int>())); |
40 | assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(ia), Iter2(ia+sa), std::greater<int>())); |
41 | |
42 | assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(ib), Iter2(ib+sb), std::greater<int>())); |
43 | assert(!std::includes(Iter1(ib), Iter1(ib+sb), Iter2(ia), Iter2(ia+sa), std::greater<int>())); |
44 | |
45 | assert(std::includes(Iter1(ia+8), Iter1(ia+sa), Iter2(ic), Iter2(ic+sc), std::greater<int>())); |
46 | assert(!std::includes(Iter1(ia+8), Iter1(ia+sa), Iter2(ib), Iter2(ib+sb), std::greater<int>())); |
47 | |
48 | assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+1), std::greater<int>())); |
49 | assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+2), std::greater<int>())); |
50 | assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+3), std::greater<int>())); |
51 | assert(!std::includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+4), std::greater<int>())); |
52 | } |
53 | |
54 | TEST_CONSTEXPR_CXX20 |
55 | bool do_tests() |
56 | { |
57 | test<cpp17_input_iterator<const int*>, cpp17_input_iterator<const int*> >(); |
58 | test<cpp17_input_iterator<const int*>, forward_iterator<const int*> >(); |
59 | test<cpp17_input_iterator<const int*>, bidirectional_iterator<const int*> >(); |
60 | test<cpp17_input_iterator<const int*>, random_access_iterator<const int*> >(); |
61 | test<cpp17_input_iterator<const int*>, const int*>(); |
62 | |
63 | test<forward_iterator<const int*>, cpp17_input_iterator<const int*> >(); |
64 | test<forward_iterator<const int*>, forward_iterator<const int*> >(); |
65 | test<forward_iterator<const int*>, bidirectional_iterator<const int*> >(); |
66 | test<forward_iterator<const int*>, random_access_iterator<const int*> >(); |
67 | test<forward_iterator<const int*>, const int*>(); |
68 | |
69 | test<bidirectional_iterator<const int*>, cpp17_input_iterator<const int*> >(); |
70 | test<bidirectional_iterator<const int*>, forward_iterator<const int*> >(); |
71 | test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*> >(); |
72 | test<bidirectional_iterator<const int*>, random_access_iterator<const int*> >(); |
73 | test<bidirectional_iterator<const int*>, const int*>(); |
74 | |
75 | test<random_access_iterator<const int*>, cpp17_input_iterator<const int*> >(); |
76 | test<random_access_iterator<const int*>, forward_iterator<const int*> >(); |
77 | test<random_access_iterator<const int*>, bidirectional_iterator<const int*> >(); |
78 | test<random_access_iterator<const int*>, random_access_iterator<const int*> >(); |
79 | test<random_access_iterator<const int*>, const int*>(); |
80 | |
81 | test<const int*, cpp17_input_iterator<const int*> >(); |
82 | test<const int*, forward_iterator<const int*> >(); |
83 | test<const int*, bidirectional_iterator<const int*> >(); |
84 | test<const int*, random_access_iterator<const int*> >(); |
85 | test<const int*, const int*>(); |
86 | |
87 | return true; |
88 | } |
89 | |
90 | int main(int, char**) |
91 | { |
92 | do_tests(); |
93 | #if TEST_STD_VER > 17 |
94 | static_assert(do_tests()); |
95 | #endif |
96 | return 0; |
97 | } |
98 | |