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 155 156 157 158 159
|
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <functional>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/set_algorithm.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
RANGES_DIAGNOSTIC_IGNORE_GLOBAL_CONSTRUCTORS
namespace
{
auto const true_ = [](bool b){CHECK(b);};
auto const false_ = [](bool b){CHECK(!b);};
template<class Iter1, class Iter2>
void
test_iter()
{
int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4};
const unsigned sa = sizeof(ia)/sizeof(ia[0]);
int ib[] = {2, 4};
const unsigned sb = sizeof(ib)/sizeof(ib[0]);
int ic[] = {1, 2};
int id[] = {3, 3, 3, 3};
auto includes = make_testable_2<true, true>(ranges::includes);
includes(Iter1(ia), Iter1(ia), Iter2(ib), Iter2(ib)).check(true_);
includes(Iter1(ia), Iter1(ia), Iter2(ib), Iter2(ib+1)).check(false_);
includes(Iter1(ia), Iter1(ia+1), Iter2(ib), Iter2(ib)).check(true_);
includes(Iter1(ia), Iter1(ia+sa), Iter2(ia), Iter2(ia+sa)).check(true_);
includes(Iter1(ia), Iter1(ia+sa), Iter2(ib), Iter2(ib+sb)).check(true_);
includes(Iter1(ib), Iter1(ib+sb), Iter2(ia), Iter2(ia+sa)).check(false_);
includes(Iter1(ia), Iter1(ia+2), Iter2(ic), Iter2(ic+2)).check(true_);
includes(Iter1(ia), Iter1(ia+2), Iter2(ib), Iter2(ib+2)).check(false_);
includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+1)).check(true_);
includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+2)).check(true_);
includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+3)).check(true_);
includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+4)).check(false_);
}
template<class Iter1, class Iter2>
void
test_comp()
{
int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4};
const unsigned sa = sizeof(ia)/sizeof(ia[0]);
int ib[] = {2, 4};
const unsigned sb = sizeof(ib)/sizeof(ib[0]);
int ic[] = {1, 2};
int id[] = {3, 3, 3, 3};
auto includes = make_testable_2<true, true>(ranges::includes);
includes(Iter1(ia), Iter1(ia), Iter2(ib), Iter2(ib), std::less<int>()).check(true_);
includes(Iter1(ia), Iter1(ia), Iter2(ib), Iter2(ib+1), std::less<int>()).check(false_);
includes(Iter1(ia), Iter1(ia+1), Iter2(ib), Iter2(ib), std::less<int>()).check(true_);
includes(Iter1(ia), Iter1(ia+sa), Iter2(ia), Iter2(ia+sa), std::less<int>()).check(true_);
includes(Iter1(ia), Iter1(ia+sa), Iter2(ib), Iter2(ib+sb), std::less<int>()).check(true_);
includes(Iter1(ib), Iter1(ib+sb), Iter2(ia), Iter2(ia+sa), std::less<int>()).check(false_);
includes(Iter1(ia), Iter1(ia+2), Iter2(ic), Iter2(ic+2), std::less<int>()).check(true_);
includes(Iter1(ia), Iter1(ia+2), Iter2(ib), Iter2(ib+2), std::less<int>()).check(false_);
includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+1), std::less<int>()).check(true_);
includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+2), std::less<int>()).check(true_);
includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+3), std::less<int>()).check(true_);
includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+4), std::less<int>()).check(false_);
}
template<class Iter1, class Iter2>
void test()
{
test_iter<Iter1, Iter2>();
test_comp<Iter1, Iter2>();
}
struct S
{
int i;
};
struct T
{
int j;
};
}
int main()
{
test<InputIterator<const int*>, InputIterator<const int*> >();
test<InputIterator<const int*>, ForwardIterator<const int*> >();
test<InputIterator<const int*>, BidirectionalIterator<const int*> >();
test<InputIterator<const int*>, RandomAccessIterator<const int*> >();
test<InputIterator<const int*>, const int*>();
test<ForwardIterator<const int*>, InputIterator<const int*> >();
test<ForwardIterator<const int*>, ForwardIterator<const int*> >();
test<ForwardIterator<const int*>, BidirectionalIterator<const int*> >();
test<ForwardIterator<const int*>, RandomAccessIterator<const int*> >();
test<ForwardIterator<const int*>, const int*>();
test<BidirectionalIterator<const int*>, InputIterator<const int*> >();
test<BidirectionalIterator<const int*>, ForwardIterator<const int*> >();
test<BidirectionalIterator<const int*>, BidirectionalIterator<const int*> >();
test<BidirectionalIterator<const int*>, RandomAccessIterator<const int*> >();
test<BidirectionalIterator<const int*>, const int*>();
test<RandomAccessIterator<const int*>, InputIterator<const int*> >();
test<RandomAccessIterator<const int*>, ForwardIterator<const int*> >();
test<RandomAccessIterator<const int*>, BidirectionalIterator<const int*> >();
test<RandomAccessIterator<const int*>, RandomAccessIterator<const int*> >();
test<RandomAccessIterator<const int*>, const int*>();
test<const int*, InputIterator<const int*> >();
test<const int*, ForwardIterator<const int*> >();
test<const int*, BidirectionalIterator<const int*> >();
test<const int*, RandomAccessIterator<const int*> >();
test<const int*, const int*>();
// Test projections
{
S ia[] = {{1}, {2}, {2}, {3}, {3}, {3}, {4}, {4}, {4}, {4}};
T id[] = {{3}, {3}, {3}};
CHECK(ranges::includes(ia, id, std::less<int>(), &S::i, &T::j));
}
{
using IL = std::initializer_list<int>;
STATIC_CHECK(ranges::includes(
IL{1, 2, 2, 3, 3, 3, 4, 4, 4, 4}, IL{3, 3, 3}, std::less<int>()));
}
return ::test_result();
}
|