BioC++ core-0.7.0
The Modern C++ libraries for Bioinformatics.
 
Loading...
Searching...
No Matches
char_strictly_to.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2022 deCODE Genetics
3// Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
4// Copyright (c) 2016-2020, Knut Reinert & MPI für molekulare Genetik
5// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
6// shipped with this file and also available at: https://github.com/biocpp/biocpp-core/blob/main/LICENSE.md
7// -----------------------------------------------------------------------------------------------------
8
14#pragma once
15
16#include <ranges>
17
25
26namespace bio::ranges::views
27{
112template <typename alphabet_type>
113 requires(alphabet::alphabet<alphabet_type> || std::same_as<alphabet_type, alphabet::cigar>)
114inline auto const char_strictly_to = detail::adaptor_from_functor{meta::overloaded{
115 // clang-format off
116 []<std::ranges::input_range rng_t>(rng_t && range)
118 std::same_as<ranges::range_innermost_value_t<rng_t>, alphabet_type>)
119 {
120 return std::forward<rng_t>(range) | views::type_reduce; // NOP
121 },
122 []<std::ranges::input_range rng_t>(rng_t && range)
124 {
125 auto fn = [] (alphabet::char_t<alphabet_type> const in) -> alphabet_type
126 {
127 return alphabet::assign_char_strictly_to(in, alphabet_type{});
128 };
129 return std::forward<rng_t>(range) | deep{std::views::transform(fn)};
130 },
131 []<typename rng_t>(rng_t &&)
132 {
133 static_assert(meta::always_false<rng_t>,
134 "The type you pass to bio::views::char_strictly_to must be a range of elements convertible "
135 "to the target alphabet's character type.");
136 }}};
137// clang-format on
138
139template <>
140inline constexpr auto char_strictly_to<bio::alphabet::cigar> = char_to<bio::alphabet::cigar>;
141
143
146template <alphabet::alphabet alph_t>
147using char_conversion_view_t = decltype(std::string_view{} | bio::views::char_strictly_to<alph_t>);
148
149} // namespace bio::ranges::views
Meta-header for the custom submodule; includes all headers from alphabet/custom/.
Provides bio::views::char_to.
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.
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
constexpr auto assign_char_strictly_to
Assign a character to an alphabet object, throw if the character is not valid.
Definition: concept.hpp:461
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
auto const char_strictly_to
A view over an alphabet, given a range of characters.
Definition: char_strictly_to.hpp:114
decltype(std::string_view{}|bio::views::char_strictly_to< alph_t >) char_conversion_view_t
A shortcut for decltype(std::string_view{} | bio::views::char_strictly_to<alph_t>).
Definition: char_strictly_to.hpp:147
The BioC++ namespace for views.
Provides bio::meta::overloaded.
Wrapper to create an overload set of multiple functors.
Definition: overloaded.hpp:37
Provides bio::views::type_reduce.
Provides various transformation traits used by the range module.