// 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 #include #include #include #include #include #include "../simple_test.hpp" #include "../test_utils.hpp" #include "../test_iterators.hpp" template void test() { int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4}; static const int sa = sizeof(ia)/sizeof(ia[0]); int ib[] = {2, 4, 4, 6}; static const int sb = sizeof(ib)/sizeof(ib[0]); int ic[20]; int ir[] = {2, 4, 4}; static const int sr = sizeof(ir)/sizeof(ir[0]); auto set_intersection = ::make_testable_2(ranges::set_intersection); set_intersection(Iter1(ia), Iter1(ia+sa), Iter2(ib), Iter2(ib+sb), OutIter(ic)).check([&](OutIter ce) { CHECK((base(ce) - ic) == sr); CHECK(std::lexicographical_compare(ic, base(ce), ir, ir+sr) == false); ranges::fill(ic, 0); }); set_intersection(Iter1(ib), Iter1(ib+sb), Iter2(ia), Iter2(ia+sa), OutIter(ic)).check([&](OutIter ce) { CHECK((base(ce) - ic) == sr); CHECK(std::lexicographical_compare(ic, base(ce), ir, ir+sr) == false); ranges::fill(ic, 0); }); set_intersection(Iter1(ia), Iter1(ia+sa), Iter2(ib), Iter2(ib+sb), OutIter(ic), std::less()).check([&](OutIter ce) { CHECK((base(ce) - ic) == sr); CHECK(std::lexicographical_compare(ic, base(ce), ir, ir+sr) == false); ranges::fill(ic, 0); }); set_intersection(Iter1(ib), Iter1(ib+sb), Iter2(ia), Iter2(ia+sa), OutIter(ic), std::less()).check([&](OutIter ce) { CHECK((base(ce) - ic) == sr); CHECK(std::lexicographical_compare(ic, base(ce), ir, ir+sr) == false); ranges::fill(ic, 0); }); } struct S { int i; }; struct T { int j; }; struct U { int k; U& operator=(S s) { k = s.i; return *this;} U& operator=(T t) { k = t.j; return *this;} }; constexpr bool test_constexpr() { using namespace ranges; int ic[20] = {0}; int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4}; int ib[4] = {2, 4, 4, 6}; int ir[3] = {2, 4, 4}; constexpr auto sr = size(ir); int * res = set_intersection(ia, ib, ic, less{}); STATIC_CHECK_RETURN((res - ic) == sr); STATIC_CHECK_RETURN(lexicographical_compare(ic, res, ir, ir + sr, less{}) == 0); return true; } int main() { #ifdef SET_INTERSECTION_1 test, InputIterator, OutputIterator >(); test, InputIterator, ForwardIterator >(); test, InputIterator, BidirectionalIterator >(); test, InputIterator, RandomAccessIterator >(); test, InputIterator, int*>(); test, ForwardIterator, OutputIterator >(); test, ForwardIterator, ForwardIterator >(); test, ForwardIterator, BidirectionalIterator >(); test, ForwardIterator, RandomAccessIterator >(); test, ForwardIterator, int*>(); test, BidirectionalIterator, OutputIterator >(); test, BidirectionalIterator, ForwardIterator >(); test, BidirectionalIterator, BidirectionalIterator >(); test, BidirectionalIterator, RandomAccessIterator >(); test, BidirectionalIterator, int*>(); test, RandomAccessIterator, OutputIterator >(); test, RandomAccessIterator, ForwardIterator >(); test, RandomAccessIterator, BidirectionalIterator >(); test, RandomAccessIterator, RandomAccessIterator >(); test, RandomAccessIterator, int*>(); test, const int*, OutputIterator >(); test, const int*, ForwardIterator >(); test, const int*, BidirectionalIterator >(); test, const int*, RandomAccessIterator >(); test, const int*, int*>(); #endif #ifdef SET_INTERSECTION_2 test, InputIterator, OutputIterator >(); test, InputIterator, ForwardIterator >(); test, InputIterator, BidirectionalIterator >(); test, InputIterator, RandomAccessIterator >(); test, InputIterator, int*>(); test, ForwardIterator, OutputIterator >(); test, ForwardIterator, ForwardIterator >(); test, ForwardIterator, BidirectionalIterator >(); test, ForwardIterator, RandomAccessIterator >(); test, ForwardIterator, int*>(); test, BidirectionalIterator, OutputIterator >(); test, BidirectionalIterator, ForwardIterator >(); test, BidirectionalIterator, BidirectionalIterator >(); test, BidirectionalIterator, RandomAccessIterator >(); test, BidirectionalIterator, int*>(); test, RandomAccessIterator, OutputIterator >(); test, RandomAccessIterator, ForwardIterator >(); test, RandomAccessIterator, BidirectionalIterator >(); test, RandomAccessIterator, RandomAccessIterator >(); test, RandomAccessIterator, int*>(); test, const int*, OutputIterator >(); test, const int*, ForwardIterator >(); test, const int*, BidirectionalIterator >(); test, const int*, RandomAccessIterator >(); test, const int*, int*>(); #endif #ifdef SET_INTERSECTION_3 test, InputIterator, OutputIterator >(); test, InputIterator, ForwardIterator >(); test, InputIterator, BidirectionalIterator >(); test, InputIterator, RandomAccessIterator >(); test, InputIterator, int*>(); test, ForwardIterator, OutputIterator >(); test, ForwardIterator, ForwardIterator >(); test, ForwardIterator, BidirectionalIterator >(); test, ForwardIterator, RandomAccessIterator >(); test, ForwardIterator, int*>(); test, BidirectionalIterator, OutputIterator >(); test, BidirectionalIterator, ForwardIterator >(); test, BidirectionalIterator, BidirectionalIterator >(); test, BidirectionalIterator, RandomAccessIterator >(); test, BidirectionalIterator, int*>(); test, RandomAccessIterator, OutputIterator >(); test, RandomAccessIterator, ForwardIterator >(); test, RandomAccessIterator, BidirectionalIterator >(); test, RandomAccessIterator, RandomAccessIterator >(); test, RandomAccessIterator, int*>(); test, const int*, OutputIterator >(); test, const int*, ForwardIterator >(); test, const int*, BidirectionalIterator >(); test, const int*, RandomAccessIterator >(); test, const int*, int*>(); #endif #ifdef SET_INTERSECTION_4 test, InputIterator, OutputIterator >(); test, InputIterator, ForwardIterator >(); test, InputIterator, BidirectionalIterator >(); test, InputIterator, RandomAccessIterator >(); test, InputIterator, int*>(); test, ForwardIterator, OutputIterator >(); test, ForwardIterator, ForwardIterator >(); test, ForwardIterator, BidirectionalIterator >(); test, ForwardIterator, RandomAccessIterator >(); test, ForwardIterator, int*>(); test, BidirectionalIterator, OutputIterator >(); test, BidirectionalIterator, ForwardIterator >(); test, BidirectionalIterator, BidirectionalIterator >(); test, BidirectionalIterator, RandomAccessIterator >(); test, BidirectionalIterator, int*>(); test, RandomAccessIterator, OutputIterator >(); test, RandomAccessIterator, ForwardIterator >(); test, RandomAccessIterator, BidirectionalIterator >(); test, RandomAccessIterator, RandomAccessIterator >(); test, RandomAccessIterator, int*>(); test, const int*, OutputIterator >(); test, const int*, ForwardIterator >(); test, const int*, BidirectionalIterator >(); test, const int*, RandomAccessIterator >(); test, const int*, int*>(); #endif #ifdef SET_INTERSECTION_5 test, OutputIterator >(); test, BidirectionalIterator >(); test, BidirectionalIterator >(); test, RandomAccessIterator >(); test, int*>(); test, OutputIterator >(); test, ForwardIterator >(); test, BidirectionalIterator >(); test, RandomAccessIterator >(); test, int*>(); test, OutputIterator >(); test, ForwardIterator >(); test, BidirectionalIterator >(); test, RandomAccessIterator >(); test, int*>(); test, OutputIterator >(); test, ForwardIterator >(); test, BidirectionalIterator >(); test, RandomAccessIterator >(); test, int*>(); test >(); test >(); test >(); test >(); test(); #endif #ifdef SET_INTERSECTION_6 // Test projections { S ia[] = {S{1}, S{2}, S{2}, S{3}, S{3}, S{3}, S{4}, S{4}, S{4}, S{4}}; T ib[] = {T{2}, T{4}, T{4}, T{6}}; U ic[20]; int ir[] = {2, 4, 4}; static const int sr = sizeof(ir)/sizeof(ir[0]); U * res = ranges::set_intersection(ranges::views::all(ia), ranges::views::all(ib), ic, std::less(), &S::i, &T::j); CHECK((res - ic) == sr); CHECK(ranges::lexicographical_compare(ic, res, ir, ir+sr, std::less(), &U::k) == false); } { STATIC_CHECK(test_constexpr()); } #endif return ::test_result(); }