From 0e8d057a2afc2b16def11424ab81492564b373e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9=20=D0=98=D0=B7?= =?UTF-8?q?=D0=B2=D0=BE=D0=BB=D0=BE=D0=B2?= Date: Sun, 19 Jul 2020 22:45:27 +0300 Subject: [PATCH] =?UTF-8?q?refs=20#121=20=D0=9F=D0=BE=D0=BB=D1=83=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D0=B5=D1=81=D0=B5=D1=87=D0=B5=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B7=D0=BD=D0=BE=D1=82=D0=B8=D0=BF=D0=BD=D1=8B?= =?UTF-8?q?=D1=85=20=D0=B4=D0=B8=D0=B0=D0=BF=D0=B0=D0=B7=D0=BE=D0=BD=D0=BE?= =?UTF-8?q?=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../burst/iterator/semiintersect_iterator.hpp | 8 +++-- test/burst/range/adaptor/semiintersected.cpp | 13 ++++++++ test/burst/range/semiintersect.cpp | 30 +++++++++++++++++++ 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/include/burst/iterator/semiintersect_iterator.hpp b/include/burst/iterator/semiintersect_iterator.hpp index c53cfa04..408668f1 100644 --- a/include/burst/iterator/semiintersect_iterator.hpp +++ b/include/burst/iterator/semiintersect_iterator.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -26,6 +27,7 @@ #include #include #include +#include #include #include @@ -474,10 +476,11 @@ namespace burst Compare compare ) { + auto common_ranges = detail::uniform_range_tuple_please(ranges); return make_semiintersect_iterator ( - burst::own_as_range(burst::apply(burst::make_range_vector, ranges)), + burst::own_as_range(burst::apply(burst::make_range_vector, common_ranges)), min_items, std::move(compare) ); @@ -496,10 +499,11 @@ namespace burst template auto make_semiintersect_iterator (std::tuple ranges, Integral min_items) { + auto common_ranges = detail::uniform_range_tuple_please(ranges); return make_semiintersect_iterator ( - burst::own_as_range(burst::apply(burst::make_range_vector, ranges)), + burst::own_as_range(burst::apply(burst::make_range_vector, common_ranges)), min_items ); } diff --git a/test/burst/range/adaptor/semiintersected.cpp b/test/burst/range/adaptor/semiintersected.cpp index 99a4f2c2..d8e27442 100644 --- a/test/burst/range/adaptor/semiintersected.cpp +++ b/test/burst/range/adaptor/semiintersected.cpp @@ -58,4 +58,17 @@ TEST_SUITE("semiintersected") const auto expected = {3, 1}; CHECK(semiintersected == expected); } + + TEST_CASE("Может работать с кортежем диапазонов") + { + const auto first = burst::make_vector ({0, 0, 1, 1, 2, 2 }); + const auto second = burst::make_vector ({0, 1, 2, 2 }); + const auto third = burst::make_forward_list({ 1, 2, 3, 4}); + // ^ ^ ^ ^ + + const auto semiintersected = std::tie(first, second, third) | burst::semiintersected(2); + + const auto expected = {0, 1, 2, 2}; + CHECK(semiintersected == expected); + } } diff --git a/test/burst/range/semiintersect.cpp b/test/burst/range/semiintersect.cpp index 8808b364..892fe115 100644 --- a/test/burst/range/semiintersect.cpp +++ b/test/burst/range/semiintersect.cpp @@ -1,3 +1,6 @@ +#include +#include +#include #include #include @@ -231,4 +234,31 @@ TEST_SUITE("semiintersect") const auto expected_collection = {0, 1, 2}; CHECK(semiintersection == expected_collection); } + + TEST_CASE("Возможно полупересечение диапазонов разных типов") + { + auto one = burst::make_vector({1, 2, 3, 4, 5, 6, 7 }); + auto two = burst::make_list ({1, 3, 5, 7, 9 }); + auto three = burst::make_deque ({1, 4, 7, 10}); + // ^ ^ ^ ^ ^ + + auto semiintersection = burst::semiintersect(std::tie(one, two, three), 2); + + auto expected_collection = {1, 3, 4, 5, 7}; + CHECK(semiintersection == expected_collection); + } + + TEST_CASE("Возможно полупересечение с предикатом диапазонов разных типов") + { + auto one = burst::make_vector({ 7, 6, 5, 4, 3, 2, 1, 0}); + auto two = burst::make_list ({ 8, 6, 4, 2, 0}); + auto three = burst::make_deque ({9, 6, 3, 0}); + // ^ ^ + + auto semiintersection = + burst::semiintersect(std::tie(one, two, three), 3, std::greater<>{}); + + auto expected_collection = {6, 0}; + CHECK(semiintersection == expected_collection); + } }