Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
148 additions
and
6 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
include/burst/iterator/detail/uniform_range_tuple_please.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#ifndef BURST_ITERATOR_DETAIL_MERGE_ITERATOR_HPP | ||
#define BURST_ITERATOR_DETAIL_MERGE_ITERATOR_HPP | ||
|
||
#include <burst/range/to_any_range.hpp> | ||
#include <burst/tuple/by_all.hpp> | ||
#include <burst/type_traits/are_same.hpp> | ||
|
||
#include <boost/iterator/iterator_categories.hpp> | ||
|
||
#include <tuple> | ||
#include <type_traits> | ||
|
||
namespace burst | ||
{ | ||
namespace detail | ||
{ | ||
/*! | ||
\brief | ||
Перегрузка для случая, когда все переданные диапазоны имеют один и тот же тип | ||
\see merge_iterator | ||
*/ | ||
template <typename... Ranges> | ||
auto uniform_range_tuple_please_impl (std::tuple<Ranges &...> ranges, std::true_type) | ||
{ | ||
static_assert(are_same_v<Ranges...>, ""); | ||
return ranges; | ||
} | ||
|
||
/*! | ||
\brief | ||
Перегрузка для случая, когда переданные диапазоны разнотипны | ||
\see merge_iterator | ||
*/ | ||
template <typename... Ranges> | ||
auto uniform_range_tuple_please_impl (std::tuple<Ranges &...> ranges, std::false_type) | ||
{ | ||
static_assert(not are_same_v<Ranges...>, ""); | ||
return by_all(to_any_range<boost::forward_traversal_tag>, ranges); | ||
} | ||
|
||
/*! | ||
\brief | ||
Сделать из кортежа возможно разнотипных диапазонов кортеж заведомо однотипных | ||
диапазонов | ||
\returns | ||
Если диапазоны изначально однотипны, то возвращается изначальный кортеж, в | ||
противном случае создаётся кортеж, в котором каждый из диапазонов приведён к | ||
boost::any_range. | ||
\see merge_iterator | ||
*/ | ||
template <typename... Ranges> | ||
auto uniform_range_tuple_please (std::tuple<Ranges &...> ranges) | ||
{ | ||
return uniform_range_tuple_please_impl(ranges, are_same<Ranges...>{}); | ||
} | ||
} | ||
} | ||
|
||
#endif // BURST_ITERATOR_DETAIL_MERGE_ITERATOR_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#ifndef BURST_RANGE_TO_ANY_RANGE_HPP | ||
#define BURST_RANGE_TO_ANY_RANGE_HPP | ||
|
||
#include <burst/type_traits/range_reference.hpp> | ||
#include <burst/type_traits/range_value.hpp> | ||
|
||
#include <boost/range/any_range.hpp> | ||
|
||
namespace burst | ||
{ | ||
template <typename Traversal> | ||
struct to_any_range_t | ||
{ | ||
template <typename Range> | ||
constexpr auto operator () (Range && range) const | ||
{ | ||
using value_type = range_value_t<Range>; | ||
using reference_type = range_reference_t<Range>; | ||
return boost::any_range<value_type, Traversal, reference_type>(range); | ||
} | ||
}; | ||
|
||
template <typename Traversal> | ||
constexpr auto to_any_range = to_any_range_t<Traversal>{}; | ||
} // namespace burst | ||
|
||
#endif // BURST_RANGE_TO_ANY_RANGE_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef BURST_TYPE_TRAITS_ARE_SAME_HPP | ||
#define BURST_TYPE_TRAITS_ARE_SAME_HPP | ||
|
||
#include <burst/type_traits/type_list.hpp> | ||
|
||
#include <type_traits> | ||
|
||
namespace burst | ||
{ | ||
template <typename T, typename... Ts> | ||
struct are_same: std::is_same<type_list<T, Ts...>, type_list<Ts..., T>> {}; | ||
|
||
template <typename... Ts> | ||
constexpr const auto are_same_v = are_same<Ts...>::value; | ||
} // namespace burst | ||
|
||
#endif // BURST_TYPE_TRAITS_ARE_SAME_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ifndef BURST_TYPE_TRAITS_TYPE_LIST_HPP | ||
#define BURST_TYPE_TRAITS_TYPE_LIST_HPP | ||
|
||
namespace burst | ||
{ | ||
template <typename... Ts> | ||
struct type_list {}; | ||
} // namespace burst | ||
|
||
#endif // BURST_TYPE_TRAITS_TYPE_LIST_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters