BioC++ core-0.7.0
The Modern C++ libraries for Bioinformatics.
 
Loading...
Searching...
No Matches
to_char.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{
28
100inline auto const to_char = detail::adaptor_from_functor{
101 meta::overloaded{// clang-format off
102 // cigar special case
103 []<std::ranges::input_range rng_t>(rng_t && range)
105 {
106 auto fn = [] (bio::alphabet::cigar const c)
107 {
108 return c.to_string();
109 };
110 return std::forward<rng_t>(range) | deep{std::views::transform(fn) | std::views::join};
111 },
112 // char2char special case
113 []<std::ranges::input_range rng_t>(rng_t && range)
117 {
118 return std::forward<rng_t>(range) | views::type_reduce; // NOP
119 },
120 // generic case
121 []<std::ranges::input_range rng_t>(rng_t && range)
123 {
124 return std::forward<rng_t>(range) | deep{std::views::transform(alphabet::to_char)};
125 },
126 // catch-all
127 []<typename rng_t>(rng_t &&)
128 {
129 static_assert(meta::always_false<rng_t>,
130 "bio::views::to_char can only be invoked with ranges over an alphabet.");
131 }}};
132// clang-format on
133
135
136} // namespace bio::ranges::views
Core alphabet concept and free function/type trait wrappers.
Meta-header for the custom submodule; includes all headers from alphabet/custom/.
Provides the bio::alphabet::cigar alphabet.
The cigar semialphabet pairs a counter with a bio::alphabet::cigar_op letter.
Definition: cigar.hpp:70
A wrapper type around an existing view adaptor that enables "deep view" behaviour for that view.
Definition: deep.hpp:104
The generic alphabet concept that covers most data types used in ranges.
Definition: concept.hpp:643
Provides bio::views::deep.
constexpr auto to_char
Return the char representation of an alphabet object.
Definition: concept.hpp:192
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
auto const to_char
A view that calls bio::alphabet::to_char() on each element in the input range.
Definition: to_char.hpp:100
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.