22namespace bio::ranges::detail
29template <std::ranges::view urng_t,
typename transform_by_pos_t>
30class view_transform_by_pos :
public std::ranges::view_base
40 static_assert(std::ranges::sized_range<urng_t>,
41 "The range parameter to views::transform_by_pos must model std::ranges::sized_range.");
42 static_assert(std::ranges::random_access_range<urng_t>,
43 "The range parameter to views::transform_by_pos must model std::ranges::random_access_range.");
46 static constexpr bool invocable = std::invocable<transform_by_pos_t, urng_t &, std::ranges::range_size_t<urng_t>>;
47 static_assert(invocable,
"Both functors need to be invocable with the range type and an integral as parameters.");
50 static constexpr bool const_invocable =
51 const_iterable_range<urng_t> &&
52 std::invocable<transform_by_pos_t const, urng_t const &, std::ranges::range_size_t<urng_t>>;
64 using difference_type = std::ranges::range_difference_t<urng_t>;
66 using size_type = size_t;
68 using iterator = detail::random_access_iterator<view_transform_by_pos>;
70 using const_iterator = detail::random_access_iterator<view_transform_by_pos const>;
74 template <
typename,
template <
typename...>
typename>
75 friend class detail::random_access_iterator_base;
81 view_transform_by_pos() noexcept = default;
82 constexpr view_transform_by_pos(view_transform_by_pos const & rhs) noexcept = default;
83 constexpr view_transform_by_pos(view_transform_by_pos && rhs) noexcept = default;
84 constexpr view_transform_by_pos & operator=(view_transform_by_pos const & rhs) noexcept = default;
85 constexpr view_transform_by_pos & operator=(view_transform_by_pos && rhs) noexcept = default;
86 ~view_transform_by_pos() noexcept = default;
93 view_transform_by_pos(urng_t _urange, transform_by_pos_t _transform_by_pos,
size_t const s) :
94 urange{std::move(_urange)},
transform_by_pos{std::move(_transform_by_pos)}, _size{s}
102 template <
typename rng_t>
103 requires(!meta::decays_to<rng_t, view_transform_by_pos> &&
104 (std::ranges::viewable_range<rng_t> &&
105 std::constructible_from<urng_t, std::ranges::ref_view<std::remove_reference_t<rng_t>>>))
106 view_transform_by_pos(rng_t && _urange, transform_by_pos_t _transform_by_pos,
size_t const s) :
107 view_transform_by_pos{
std::views::all(
std::
forward<rng_t>(_urange)),
std::
move(_transform_by_pos), s}
127 auto begin() noexcept {
return iterator{*
this, 0}; }
129 auto begin() const noexcept
130 requires const_invocable
132 return const_iterator{*
this, 0};
148 auto end() noexcept {
return iterator{*
this,
size()}; }
150 auto end() const noexcept
151 requires const_invocable
153 return const_iterator{*
this,
size()};
168 size_t size() const noexcept {
return _size; }
188 decltype(
auto)
operator[](
size_t const n)
195 decltype(
auto)
operator[](
size_t const n)
const
196 requires const_invocable
205template <
typename urng_t,
typename transform_by_pos_t>
206view_transform_by_pos(urng_t &&, transform_by_pos_t,
size_t)
207 -> view_transform_by_pos<std::views::all_t<urng_t>, transform_by_pos_t>;
214struct transform_by_pos_fn
217 template <
typename transform_by_pos_t,
typename size_transform_t = std::remove_cvref_t<decltype(std::ranges::size)>>
218 constexpr auto operator()(transform_by_pos_t transform_by_pos,
219 size_transform_t size_transform = std::ranges::size)
const
221 return detail::adaptor_from_functor{*
this, std::move(transform_by_pos), std::move(size_transform)};
230 template <std::ranges::range urng_t,
231 typename transform_by_pos_t,
233 constexpr auto operator()(urng_t && urange,
235 size_transform_t size_transform = std::ranges::size)
const
237 static_assert(std::ranges::viewable_range<urng_t>,
238 "The range parameter to views::transform_by_pos must viewable.");
239 static_assert(std::ranges::sized_range<urng_t>,
240 "The range parameter to views::transform_by_pos must model std::ranges::sized_range.");
241 static_assert(std::ranges::random_access_range<urng_t>,
242 "The range parameter to views::transform_by_pos must model std::ranges::random_access_range.");
243 static_assert(std::convertible_to<std::invoke_result_t<size_transform_t, urng_t &>,
size_t>,
244 "The size_transform must be invocable with `urng_t &` and return sth. convertible to size_t.");
246 return view_transform_by_pos{std::forward<urng_t>(urange), std::move(transform_by_pos), size_transform(urange)};
constexpr auto size
A type trait that holds the size of a (semi-)alphabet.
Definition: concept.hpp:517
constexpr auto transform_by_pos
A view adaptor similar to std::views::transform. Calls the invocable with two arguments: underlying r...
Definition: transform_by_pos.hpp:313
The BioC++ namespace for views.
Provides the bio::ranges::detail::random_access_iterator class.
Additional non-standard concepts for ranges.
Auxiliary header for the views submodule .