1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14
// UNSUPPORTED: libcpp-has-no-incomplete-pstl
// <algorithm>
// template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
// bool equal(ExecutionPolicy&& exec,
// ForwardIterator1 first1, ForwardIterator1 last1,
// ForwardIterator2 first2);
//
// template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
// class BinaryPredicate>
// bool equal(ExecutionPolicy&& exec,
// ForwardIterator1 first1, ForwardIterator1 last1,
// ForwardIterator2 first2, BinaryPredicate pred);
//
// template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
// bool equal(ExecutionPolicy&& exec,
// ForwardIterator1 first1, ForwardIterator1 last1,
// ForwardIterator2 first2, ForwardIterator2 last2);
//
// template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
// class BinaryPredicate>
// bool equal(ExecutionPolicy&& exec,
// ForwardIterator1 first1, ForwardIterator1 last1,
// ForwardIterator2 first2, ForwardIterator2 last2,
// BinaryPredicate pred);
#include <algorithm>
#include <cassert>
#include <iterator>
#include "test_execution_policies.h"
#include "test_iterators.h"
#include "test_macros.h"
template <class It1, class It2>
struct Test {
template <class Policy>
void operator()(Policy&& policy) {
{ // 3 iter overloads
// check with equal ranges
{
int a[] = {1, 2, 3, 4};
int b[] = {1, 2, 3, 4};
assert(std::equal(policy, It1(std::begin(a)), It1(std::end(a)), It2(std::begin(b))));
}
// check with an empty range
{
int a[] = {999};
int b[] = {1, 2, 3};
assert(std::equal(policy, It1(std::begin(a)), It1(std::begin(a)), It2(std::begin(b))));
}
// check with different ranges
{
int a[] = {1, 2, 3};
int b[] = {3, 2, 1};
assert(!std::equal(policy, It1(std::begin(a)), It1(std::end(a)), It2(std::begin(b))));
}
// check that the predicate is used
{
int a[] = {2, 4, 6, 8, 10};
int b[] = {12, 14, 16, 18, 20};
assert(std::equal(policy, It1(std::begin(a)), It1(std::end(a)), It2(std::begin(b)), [](int lhs, int rhs) {
return lhs % 2 == rhs % 2;
}));
}
}
{ // 4 iter overloads
// check with equal ranges of equal size
{
int a[] = {1, 2, 3, 4};
int b[] = {1, 2, 3, 4};
assert(std::equal(policy, It1(std::begin(a)), It1(std::end(a)), It2(std::begin(b)), It2(std::end(b))));
}
// check with unequal ranges of equal size
{
int a[] = {1, 2, 3, 4};
int b[] = {4, 3, 2, 1};
assert(!std::equal(policy, It1(std::begin(a)), It1(std::end(a)), It2(std::begin(b)), It2(std::end(b))));
}
// check with equal ranges of unequal size
{
{
int a[] = {1, 2, 3, 4};
int b[] = {1, 2, 3, 4, 5};
assert(!std::equal(policy, It1(std::begin(a)), It1(std::end(a)), It2(std::begin(b)), It2(std::end(b))));
}
{
int a[] = {1, 2, 3, 4, 5};
int b[] = {1, 2, 3, 4};
assert(!std::equal(policy, It1(std::begin(a)), It1(std::end(a)), It2(std::begin(b)), It2(std::end(b))));
}
}
// check empty ranges
{
// empty/empty
{
int a[] = {888};
int b[] = {999};
assert(std::equal(policy, It1(std::begin(a)), It1(std::begin(a)), It2(std::begin(b)), It2(std::begin(b))));
}
// empty/non-empty
{
int a[] = {999};
int b[] = {999};
assert(!std::equal(policy, It1(std::begin(a)), It1(std::begin(a)), It2(std::begin(b)), It2(std::end(b))));
}
// non-empty/empty
{
int a[] = {999};
int b[] = {999};
assert(!std::equal(policy, It1(std::begin(a)), It1(std::end(a)), It2(std::begin(b)), It2(std::begin(b))));
}
}
// check that the predicate is used
{
int a[] = {2, 4, 6, 8, 10};
int b[] = {12, 14, 16, 18, 20};
assert(std::equal(
policy, It1(std::begin(a)), It1(std::end(a)), It2(std::begin(b)), It2(std::end(b)), [](int lhs, int rhs) {
return lhs % 2 == rhs % 2;
}));
}
}
}
};
int main(int, char**) {
types::for_each(types::forward_iterator_list<int*>{}, types::apply_type_identity{[](auto v) {
using It1 = typename decltype(v)::type;
types::for_each(
types::forward_iterator_list<int*>{},
TestIteratorWithPolicies<types::partial_instantiation<Test, It1>::template apply>{});
}});
return 0;
}
|