25namespace seqan3::detail
43template <std::ranges::random_access_range urng_t, std::ranges::random_access_range inserted_rng_t>
44 requires std::ranges::view<urng_t> && std::ranges::sized_range<urng_t> && std::ranges::view<inserted_rng_t>
45 && std::ranges::sized_range<inserted_rng_t>
46 && std::common_reference_with<std::ranges::range_reference_t<urng_t>,
47 std::ranges::range_reference_t<inserted_rng_t>>
48class view_interleave :
public std::ranges::view_interface<view_interleave<urng_t, inserted_rng_t>>
56 inserted_rng_t inserted_range;
63 using size_type = std::ranges::range_size_t<urng_t>;
68 using const_reference =
69 detail::transformation_trait_or_t<std::common_reference<std::ranges::range_reference_t<urng_t const>,
70 std::ranges::range_reference_t<inserted_rng_t const>>,
73 using value_type = std::ranges::range_value_t<urng_t>;
75 using difference_type = std::ranges::range_difference_t<urng_t>;
77 using iterator = detail::random_access_iterator<view_interleave>;
79 using const_iterator = detail::random_access_iterator<view_interleave const>;
83 template <
typename range_type,
template <
typename...>
typename derived_t_template,
typename... args_t>
84 friend class detail::random_access_iterator_base;
90 constexpr view_interleave() noexcept = default;
91 constexpr view_interleave(view_interleave const & rhs) noexcept = default;
92 constexpr view_interleave(view_interleave && rhs) noexcept = default;
93 constexpr view_interleave & operator=(view_interleave const & rhs) noexcept = default;
94 constexpr view_interleave & operator=(view_interleave && rhs) noexcept = default;
95 ~view_interleave() noexcept = default;
102 explicit constexpr view_interleave(urng_t && _urange,
size_t const _step_size, inserted_rng_t && _inserted_range) :
104 step_size{_step_size},
105 inserted_range{std::forward<inserted_rng_t>(_inserted_range)}
117 template <
typename orng_t,
typename oirng_t>
118 requires std::constructible_from<urng_t, decltype(views::type_reduce(std::declval<orng_t>()))>
119 && std::constructible_from<inserted_rng_t, seqan3::detail::all_t<oirng_t>>
120 explicit constexpr view_interleave(orng_t && _urange,
size_t const _step_size, oirng_t && _inserted_range) :
121 view_interleave{views::type_reduce(
std::
forward<orng_t>(_urange)),
143 iterator
begin() noexcept
149 const_iterator
begin() const noexcept
167 iterator
end() noexcept
169 return {*
this,
size()};
173 const_iterator
end() const noexcept
175 return {*
this,
size()};
189 return std::ranges::size(urange)
190 + ((
std::floor(std::ranges::size(urange) / step_size)
191 - (std::ranges::size(urange) % step_size == 0 ? 1 : 0))
192 * std::ranges::size(inserted_range));
196 size_type
size()
const
198 return std::ranges::size(urange)
199 + ((
std::floor(std::ranges::size(urange) / step_size)
200 - (std::ranges::size(urange) % step_size == 0 ? 1 : 0))
201 * std::ranges::size(inserted_range));
219 reference operator[](size_type
const i)
221 size_t combined_size = step_size + std::ranges::size(inserted_range);
223 if (i % (combined_size) < step_size)
224 return urange[i - (
std::floor(i / (combined_size)) * std::ranges::size(inserted_range))];
226 return inserted_range[(i % (combined_size)) - step_size];
230 const_reference operator[](size_type
const i)
const
232 size_t combined_size = step_size + std::ranges::size(inserted_range);
234 if (i % (combined_size) < step_size)
235 return urange[i - (
std::floor(i / (combined_size)) * std::ranges::size(inserted_range))];
237 return inserted_range[(i % (combined_size)) - step_size];
243template <std::ranges::random_access_range urng_t, std::ranges::random_access_range inserted_rng_t>
244 requires std::ranges::viewable_range<urng_t> && std::ranges::sized_range<urng_t>
245 && std::ranges::sized_range<inserted_rng_t>
246 && std::common_reference_with<std::ranges::range_reference_t<urng_t>,
247 std::ranges::range_reference_t<inserted_rng_t>>
248view_interleave(urng_t &&,
size_t, inserted_rng_t &&)
249 -> view_interleave<decltype(views::type_reduce(std::declval<urng_t>())), seqan3::detail::all_t<inserted_rng_t>>;
260 template <std::ranges::forward_range inserted_rng_t, std::
integral
size_type>
261 constexpr auto operator()(size_type
const size, inserted_rng_t && i)
const noexcept
263 return detail::adaptor_from_functor{*
this,
size, std::forward<inserted_rng_t>(i)};
272 template <std::ranges::range urng_t, std::ranges::range inserted_rng_t, std::
integral
size_type>
273 constexpr auto operator()(urng_t && urange, size_type
const size, inserted_rng_t && i)
const noexcept
275 static_assert(std::ranges::forward_range<urng_t>,
276 "The underlying range parameter in views::interleave must model std::ranges::forward_range.");
277 static_assert(std::ranges::viewable_range<urng_t>,
278 "The underlying range parameter in views::interleave must model std::ranges::viewable_range.");
279 static_assert(std::ranges::forward_range<inserted_rng_t>,
280 "The range to be inserted by views::interleave must model std::ranges::forward_range.");
281 if constexpr (std::ranges::random_access_range<urng_t> && std::ranges::sized_range<urng_t>
282 && std::ranges::random_access_range<inserted_rng_t> && std::ranges::sized_range<inserted_rng_t>)
284 return detail::view_interleave{std::forward<urng_t>(urange),
285 static_cast<size_t>(
size),
286 std::forward<inserted_rng_t>(i)};
Provides seqan3::detail::adaptor_from_functor.
Provides seqan3::detail::all.
Provides seqan3::views::chunk.
constexpr size_t size
The size of a type pack.
Definition type_pack/traits.hpp:143
seqan::stl::views::join_with join_with
A view adaptor that represents view consisting of the sequence obtained from flattening a view of ran...
Definition join_with.hpp:25
seqan::stl::views::chunk chunk
A view adaptor that divides a range into chunks. <dl class="no-api">This entity is not part of the Se...
Definition chunk.hpp:23
constexpr auto interleave
A view that interleaves a given range into another range at regular intervals.
Definition interleave.hpp:375
Provides seqan3::views::join_with.
The SeqAn namespace for views.
Definition char_strictly_to.hpp:19
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
SeqAn specific customisations in the standard namespace.
Provides the seqan3::detail::random_access_iterator class.
Provides seqan3::views::type_reduce.