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