28#include "bio/alphabet/detail/to_lower.hpp"
32namespace bio::ranges::detail
45template <std::ranges::view urng_t>
46 requires std::ranges::forward_range<urng_t>
47class char_to_cigar_view :
public std::ranges::view_interface<char_to_cigar_view<urng_t>>
54 template <
typename uit_t,
typename usen_t>
58 using it_t = iterator<std::ranges::iterator_t<urng_t>, std::ranges::sentinel_t<urng_t>>;
62 iterator<std::ranges::iterator_t<urng_t const>, std::ranges::sentinel_t<urng_t const>>,
69 char_to_cigar_view() =
default;
70 char_to_cigar_view(char_to_cigar_view
const &) =
default;
71 char_to_cigar_view & operator=(char_to_cigar_view
const &) =
default;
72 char_to_cigar_view(char_to_cigar_view &&) noexcept = default;
73 char_to_cigar_view & operator=(char_to_cigar_view &&) noexcept = default;
74 ~char_to_cigar_view() = default;
77 constexpr explicit char_to_cigar_view(urng_t _urange) : urange{std::move(_urange)} {}
98 constexpr auto begin() noexcept
104 constexpr auto begin() const noexcept
105 requires const_iterable_range<urng_t>
125 constexpr auto end() noexcept
127 if constexpr (std::ranges::common_range<urng_t>)
128 return it_t{std::ranges::end(urange),
std::ranges::begin(urange), std::ranges::end(urange)};
130 return std::ranges::end(urange);
134 constexpr auto end() const noexcept
135 requires const_iterable_range<urng_t>
137 if constexpr (std::ranges::common_range<urng_t>)
138 return const_it_t{std::ranges::end(urange),
std::ranges::begin(urange), std::ranges::end(urange)};
140 return std::ranges::end(urange);
149template <std::ranges::view urng_t>
150 requires std::ranges::forward_range<urng_t>
151template <
typename uit_t,
typename usen_t>
152class char_to_cigar_view<urng_t>::iterator
156 static constexpr alphabet::cigar default_value{(2u << 28) - 1,
alphabet::assign_char_to(
'B', alphabet::cigar_op{})};
159 static constexpr bool is_digit(
char const c) {
return c >=
'0' && c <=
'9'; }
162 static constexpr bool is_alpha(
char const c)
164 return alphabet::detail::is_lower(c) || alphabet::detail::is_upper(c);
176 alphabet::cigar value = default_value;
179 static constexpr bool nothrow_default_init =
180 std::is_nothrow_default_constructible_v<uit_t> && std::is_nothrow_default_constructible_v<usen_t>;
182 static constexpr bool nothrow_move_init =
183 std::is_nothrow_move_constructible_v<uit_t> && std::is_nothrow_move_constructible_v<usen_t>;
185 static constexpr bool nothrow_copy_init =
186 std::is_nothrow_copy_constructible_v<uit_t> && std::is_nothrow_copy_constructible_v<usen_t>;
188 static constexpr bool nothrow_move_assign =
189 std::is_nothrow_move_assignable_v<uit_t> && std::is_nothrow_move_assignable_v<usen_t>;
191 static constexpr bool nothrow_copy_assign =
192 std::is_nothrow_copy_assignable_v<uit_t> && std::is_nothrow_copy_assignable_v<usen_t>;
203 using value_type = alphabet::cigar;
205 using reference = alphabet::cigar;
207 using pointer =
void *;
213 detail::iterator_concept_tag_t<uit_t>>;
220 constexpr iterator() noexcept(nothrow_default_init) = default;
221 constexpr iterator(iterator const & rhs) noexcept(nothrow_copy_init) = default;
222 constexpr iterator(iterator && rhs) noexcept(nothrow_move_init) = default;
223 constexpr iterator & operator=(iterator const & rhs) noexcept(nothrow_copy_assign) = default;
224 constexpr iterator & operator=(iterator && rhs) noexcept(nothrow_move_assign) = default;
225 ~iterator() noexcept(
std::is_nothrow_destructible_v<uit_t>) = default;
228 constexpr iterator(uit_t const it, uit_t const beg, usen_t const sen) noexcept(nothrow_copy_init) :
229 uit_left{it}, uit_right{it}, ubeg{beg}, usen{sen}
238 constexpr friend bool operator==(iterator
const & lhs, iterator
const & rhs)
noexcept(
239 noexcept(std::declval<uit_t &>() == std::declval<uit_t &>()))
241 return lhs.uit_left == rhs.uit_left;
245 constexpr friend bool operator==(iterator
const & lhs, usen_t
const & rhs)
noexcept(
246 noexcept(std::declval<uit_t &>() == std::declval<usen_t &>()))
247 requires(!std::same_as<uit_t, usen_t>)
249 return lhs.uit_left == rhs;
253 constexpr friend auto operator<=>(iterator
const & lhs, iterator
const & rhs)
noexcept(
254 noexcept(std::declval<uit_t &>() < std::declval<uit_t &>()))
255 requires std::totally_ordered<uit_t>
257 return lhs.uit_left <=> rhs.uit_left;
266 constexpr iterator & operator++()
268 value = default_value;
270 if (uit_left != uit_right)
271 uit_left = uit_right;
273 if (uit_left == usen)
276 while (!is_alpha(*uit_right))
278 assert(is_digit(*uit_right));
280 assert(uit_right != usen);
289 constexpr auto operator++(
int)
297 constexpr iterator & operator--()
298 requires(
requires(uit_t i) { --i; })
300 assert(uit_left != ubeg);
302 value = default_value;
304 uit_right = uit_left;
307 assert(is_alpha(*uit_left));
313 while (is_digit(*uit_left) && uit_left != ubeg);
315 if (uit_left != ubeg)
322 constexpr auto operator--(
int)
323 requires(
requires(uit_t i) { --i; })
335 constexpr value_type operator*()
337 if (value == default_value)
339 if constexpr (std::contiguous_iterator<uit_t>)
342 value.assign_string(v);
348 value.assign_string(s);
355 constexpr value_type operator*()
const
359 if constexpr (std::contiguous_iterator<uit_t>)
374 constexpr pointer operator->() noexcept(noexcept(*
std::declval<uit_t &>()))
375 requires
std::input_iterator<uit_t>
381 constexpr decltype(
auto) operator->() const noexcept(noexcept(*
std::declval<uit_t const &>()))
382 requires
std::input_iterator<uit_t>
397template <
typename urng_t>
398inline constexpr bool std::ranges::enable_borrowed_range<bio::ranges::detail::char_to_cigar_view<urng_t>> =
399 std::ranges::borrowed_range<urng_t>;
489template <
typename alphabet_type>
490 requires(alphabet::alphabet<alphabet_type> || std::same_as<alphabet_type, alphabet::cigar>)
495 []<std::ranges::input_range rng_t>(rng_t && range)
502 []<std::ranges::input_range rng_t>(rng_t && range)
509 return std::forward<rng_t>(range) |
deep{std::views::transform(fn)};
512 []<
typename rng_t>(rng_t &&)
514 static_assert(meta::always_false<rng_t>,
515 "The type you pass to bio::views::char_to must be a range of elements convertible "
516 "to the target alphabet's character type.");
521inline constexpr auto char_to<alphabet::cigar> = detail::adaptor_from_functor{
523 []<
typename rng_t>(rng_t && range)
525 static_assert(std::ranges::forward_range<rng_t> && std::same_as<std::ranges::range_value_t<rng_t>,
char>,
526 "The type you pass to bio::views::char_to<bio::alphabet::cigar> must be a forward_range "
Meta-header for the custom submodule; includes all headers from alphabet/custom/.
T back_inserter(T... args)
Provides the bio::alphabet::cigar alphabet.
A wrapper type around an existing view adaptor that enables "deep view" behaviour for that view.
Definition: deep.hpp:104
Provides bio::views::deep.
Exceptions thrown by entities in the alphabet module.
constexpr auto assign_char_to
Assign a char to an alphabet object.
Definition: concept.hpp:260
decltype(bio::alphabet::to_char(std::declval< alphabet_type const >())) char_t
The char_type of the alphabet; defined as the return type of bio::alphabet::to_char.
Definition: concept.hpp:212
typename range_innermost_value< t >::type range_innermost_value_t
Shortcut for bio::ranges::range_innermost_value (transformation_trait shortcut).
Definition: type_traits.hpp:185
constexpr auto type_reduce
A view adaptor that behaves like std::views::all, but type erases certain ranges.
Definition: type_reduce.hpp:152
constexpr auto char_to
A view over an alphabet, given a range of characters.
Definition: char_to.hpp:491
The BioC++ namespace for views.
Provides bio::meta::overloaded.
Additional non-standard concepts for ranges.
A constexpr string implementation to manipulate string literals at compile time.
Provides bio::views::type_reduce.
Provides various transformation traits used by the range module.