Skip to content

Commit

Permalink
refs #121 Склейка разнотипных диапазонов
Browse files Browse the repository at this point in the history
  • Loading branch information
izvolov committed Jul 24, 2020
1 parent 96bccc8 commit c5cc644
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
6 changes: 4 additions & 2 deletions include/burst/iterator/join_iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define BURST_ITERATOR_JOIN_ITERATOR_HPP

#include <burst/iterator/detail/join_iterator.hpp>
#include <burst/iterator/detail/uniform_range_tuple_please.hpp>
#include <burst/iterator/end_tag.hpp>
#include <burst/range/make_range_vector.hpp>
#include <burst/range/own_as_range.hpp>
Expand All @@ -13,6 +14,7 @@
#include <boost/iterator/minimum_category.hpp>

#include <iterator>
#include <tuple>
#include <utility>

namespace burst
Expand Down Expand Up @@ -139,8 +141,8 @@ namespace burst
template <typename ... Ranges>
auto make_join_iterator (std::tuple<Ranges &...> ranges)
{
return
make_join_iterator(burst::own_as_range(burst::apply(burst::make_range_vector, ranges)));
auto common_ranges = detail::uniform_range_tuple_please(ranges);
return make_join_iterator(own_as_range(burst::apply(make_range_vector, common_ranges)));
}

//! Функция для создания итератора на конец склейки.
Expand Down
14 changes: 14 additions & 0 deletions test/burst/iterator/join_iterator.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <burst/container/make_deque.hpp>
#include <burst/container/make_forward_list.hpp>
#include <burst/container/make_vector.hpp>
#include <burst/iterator/join_iterator.hpp>
Expand Down Expand Up @@ -39,6 +40,19 @@ TEST_SUITE("join_iterator")
BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<decltype(joined_end)>));
}

TEST_CASE("Итератор склейки, созданный из диапазонов произвольного доступа (с помощью "
"кортежа) — итератор произвольного доступа")
{
auto first = burst::make_vector({3, 2});
auto second = burst::make_deque({1, 0});

auto joined_begin = burst::make_join_iterator(std::tie(first, second));
auto joined_end = burst::make_join_iterator(burst::iterator::end_tag, joined_begin);

BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<decltype(joined_begin)>));
BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<decltype(joined_end)>));
}

TEST_CASE("Уменьшение итератора склейки произвольного доступа допустимо")
{
auto first = {3, 2};
Expand Down
13 changes: 13 additions & 0 deletions test/burst/range/adaptor/joined.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <burst/container/make_forward_list.hpp>
#include <burst/container/make_vector.hpp>
#include <burst/range/adaptor/joined.hpp>
#include <burst/range/make_range_vector.hpp>
#include <utility/io/initializer_list.hpp>
Expand Down Expand Up @@ -35,4 +36,16 @@ TEST_SUITE("joined")
const auto expected = boost::irange(0, 20);
CHECK(joined == expected);
}

TEST_CASE("Может работать с кортежем диапазонов")
{
const auto first = burst::make_vector({0, 1});
const auto second = burst::make_vector({2, 3});
const auto third = burst::make_forward_list({4, 5});

const auto joined = std::tie(first, second, third) | burst::joined;

const auto expected = {0, 1, 2, 3, 4, 5};
CHECK(joined == expected);
}
}
13 changes: 13 additions & 0 deletions test/burst/range/join.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <burst/container/make_deque.hpp>
#include <burst/container/make_list.hpp>
#include <burst/container/make_vector.hpp>
#include <burst/range/join.hpp>
Expand Down Expand Up @@ -217,4 +218,16 @@ TEST_SUITE("join")
const auto expected_collection = {'1', '2', '3'};
CHECK(joint_range == expected_collection);
}

TEST_CASE("Может склеивать диапазоны разных типов")
{
auto one = burst::make_vector({1, 2});
auto two = burst::make_list({3, 4});
auto three = burst::make_deque({5, 6});

auto joint_range = burst::join(std::tie(one, two, three));

auto expected_collection = {1, 2, 3, 4, 5, 6};
CHECK(joint_range == expected_collection);
}
}

0 comments on commit c5cc644

Please sign in to comment.