1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <algorithm>
11
12 // template<InputIterator Iter1, InputIterator Iter2,
13 // Predicate<auto, Iter1::value_type, Iter2::value_type> Pred>
14 // requires CopyConstructible<Pred>
15 // bool
16 // equal(Iter1 first1, Iter1 last1, Iter2 first2, Pred pred);
17
18 #include <algorithm>
19 #include <functional>
20 #include <cassert>
21
22 #include "test_macros.h"
23 #include "test_iterators.h"
24
25 int comparison_count = 0;
26 template <typename T>
counting_equals(const T & a,const T & b)27 bool counting_equals ( const T &a, const T &b ) {
28 ++comparison_count;
29 return a == b;
30 }
31
main()32 int main()
33 {
34 int ia[] = {0, 1, 2, 3, 4, 5};
35 const unsigned s = sizeof(ia)/sizeof(ia[0]);
36 int ib[s] = {0, 1, 2, 5, 4, 5};
37 assert(std::equal(input_iterator<const int*>(ia),
38 input_iterator<const int*>(ia+s),
39 input_iterator<const int*>(ia),
40 std::equal_to<int>()));
41 #if TEST_STD_VER >= 14
42 assert(std::equal(input_iterator<const int*>(ia),
43 input_iterator<const int*>(ia+s),
44 input_iterator<const int*>(ia),
45 input_iterator<const int*>(ia+s),
46 std::equal_to<int>()));
47 assert(std::equal(random_access_iterator<const int*>(ia),
48 random_access_iterator<const int*>(ia+s),
49 random_access_iterator<const int*>(ia),
50 random_access_iterator<const int*>(ia+s),
51 std::equal_to<int>()));
52
53 comparison_count = 0;
54 assert(!std::equal(input_iterator<const int*>(ia),
55 input_iterator<const int*>(ia+s),
56 input_iterator<const int*>(ia),
57 input_iterator<const int*>(ia+s-1),
58 counting_equals<int>));
59 assert(comparison_count > 0);
60 comparison_count = 0;
61 assert(!std::equal(random_access_iterator<const int*>(ia),
62 random_access_iterator<const int*>(ia+s),
63 random_access_iterator<const int*>(ia),
64 random_access_iterator<const int*>(ia+s-1),
65 counting_equals<int>));
66 assert(comparison_count == 0);
67 #endif
68 assert(!std::equal(input_iterator<const int*>(ia),
69 input_iterator<const int*>(ia+s),
70 input_iterator<const int*>(ib),
71 std::equal_to<int>()));
72 #if TEST_STD_VER >= 14
73 assert(!std::equal(input_iterator<const int*>(ia),
74 input_iterator<const int*>(ia+s),
75 input_iterator<const int*>(ib),
76 input_iterator<const int*>(ib+s),
77 std::equal_to<int>()));
78 assert(!std::equal(random_access_iterator<const int*>(ia),
79 random_access_iterator<const int*>(ia+s),
80 random_access_iterator<const int*>(ib),
81 random_access_iterator<const int*>(ib+s),
82 std::equal_to<int>()));
83 #endif
84 }
85