1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
11 // template<InputIterator Iter1, InputIterator Iter2,
12 // Predicate<auto, Iter1::value_type, Iter2::value_type> Pred>
13 // requires CopyConstructible<Pred>
14 // constexpr bool // constexpr after c++17
15 // equal(Iter1 first1, Iter1 last1, Iter2 first2, Pred pred);
17 // Introduced in C++14:
18 // template<InputIterator Iter1, InputIterator Iter2,
19 // Predicate<auto, Iter1::value_type, Iter2::value_type> Pred>
20 // requires CopyConstructible<Pred>
21 // constexpr bool // constexpr after c++17
22 // equal(Iter1 first1, Iter1 last1, Iter2 first2, Iter2 last2, Pred pred);
29 #include "test_macros.h"
30 #include "test_iterators.h"
33 TEST_CONSTEXPR
bool eq(int a
, int b
) { return a
== b
; }
35 TEST_CONSTEXPR
bool test_constexpr() {
36 int ia
[] = {1, 3, 6, 7};
38 int ic
[] = {1, 3, 5, 7};
39 typedef input_iterator
<int*> II
;
40 typedef bidirectional_iterator
<int*> BI
;
42 return !std::equal(std::begin(ia
), std::end(ia
), std::begin(ic
) , eq
)
43 && !std::equal(std::begin(ia
), std::end(ia
), std::begin(ic
), std::end(ic
), eq
)
44 && std::equal(std::begin(ib
), std::end(ib
), std::begin(ic
) , eq
)
45 && !std::equal(std::begin(ib
), std::end(ib
), std::begin(ic
), std::end(ic
), eq
)
47 && std::equal(II(std::begin(ib
)), II(std::end(ib
)), II(std::begin(ic
)) , eq
)
48 && !std::equal(BI(std::begin(ib
)), BI(std::end(ib
)), BI(std::begin(ic
)), BI(std::end(ic
)), eq
)
54 int comparison_count
= 0;
56 bool counting_equals ( const T
&a
, const T
&b
) {
63 int ia
[] = {0, 1, 2, 3, 4, 5};
64 const unsigned s
= sizeof(ia
)/sizeof(ia
[0]);
65 int ib
[s
] = {0, 1, 2, 5, 4, 5};
66 assert(std::equal(input_iterator
<const int*>(ia
),
67 input_iterator
<const int*>(ia
+s
),
68 input_iterator
<const int*>(ia
),
69 std::equal_to
<int>()));
70 #if TEST_STD_VER >= 14
71 assert(std::equal(input_iterator
<const int*>(ia
),
72 input_iterator
<const int*>(ia
+s
),
73 input_iterator
<const int*>(ia
),
74 input_iterator
<const int*>(ia
+s
),
75 std::equal_to
<int>()));
76 assert(std::equal(random_access_iterator
<const int*>(ia
),
77 random_access_iterator
<const int*>(ia
+s
),
78 random_access_iterator
<const int*>(ia
),
79 random_access_iterator
<const int*>(ia
+s
),
80 std::equal_to
<int>()));
83 assert(!std::equal(input_iterator
<const int*>(ia
),
84 input_iterator
<const int*>(ia
+s
),
85 input_iterator
<const int*>(ia
),
86 input_iterator
<const int*>(ia
+s
-1),
87 counting_equals
<int>));
88 assert(comparison_count
> 0);
90 assert(!std::equal(random_access_iterator
<const int*>(ia
),
91 random_access_iterator
<const int*>(ia
+s
),
92 random_access_iterator
<const int*>(ia
),
93 random_access_iterator
<const int*>(ia
+s
-1),
94 counting_equals
<int>));
95 assert(comparison_count
== 0);
97 assert(!std::equal(input_iterator
<const int*>(ia
),
98 input_iterator
<const int*>(ia
+s
),
99 input_iterator
<const int*>(ib
),
100 std::equal_to
<int>()));
101 #if TEST_STD_VER >= 14
102 assert(!std::equal(input_iterator
<const int*>(ia
),
103 input_iterator
<const int*>(ia
+s
),
104 input_iterator
<const int*>(ib
),
105 input_iterator
<const int*>(ib
+s
),
106 std::equal_to
<int>()));
107 assert(!std::equal(random_access_iterator
<const int*>(ia
),
108 random_access_iterator
<const int*>(ia
+s
),
109 random_access_iterator
<const int*>(ib
),
110 random_access_iterator
<const int*>(ib
+s
),
111 std::equal_to
<int>()));
114 #if TEST_STD_VER > 17
115 static_assert(test_constexpr());