SeqAn3  3.0.0
The Modern C++ library for sequence analysis.
char.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2019, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2019, Knut Reinert & MPI für molekulare Genetik
4 // This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5 // shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
6 // -----------------------------------------------------------------------------------------------------
7 
26 #pragma once
27 
28 #include <limits>
29 
31 #include <seqan3/std/concepts>
32 
33 namespace seqan3::detail
34 {
37 
39 template <typename type, typename type_no_ref = std::remove_reference_t<type>>
40 constexpr bool is_char_adaptation_v = std::Same<type_no_ref, char> ||
45 } // namespace seqan3::detail
46 
47 namespace seqan3::custom
48 {
49 
61 template <typename char_type>
63  requires seqan3::detail::is_char_adaptation_v<char_type>
65 constexpr auto alphabet_size(char_type const & SEQAN3_DOXYGEN_ONLY(chr)) noexcept
66 {
67  return detail::min_viable_uint_t<detail::size_in_values_v<char_type>>{detail::size_in_values_v<char_type>};
68 }
69 
75 template <typename char_type>
77  requires seqan3::detail::is_char_adaptation_v<char_type>
79 constexpr char_type to_char(char_type const chr) noexcept
80 {
81  return chr;
82 }
83 
89 template <typename char_type>
91  requires seqan3::detail::is_char_adaptation_v<char_type>
93 constexpr auto to_rank(char_type const chr) noexcept
94 {
95  return static_cast<::seqan3::detail::min_viable_uint_t<alphabet_size(char_type{}) - 1>>(chr);
96 }
97 
104 template <typename char_type>
106  requires detail::is_char_adaptation_v<char_type>
108 constexpr char_type & assign_char_to(char_type const chr2, char_type & chr) noexcept
109 {
110  return chr = chr2;
111 }
112 
119 template <typename char_type>
121  requires detail::is_char_adaptation_v<char_type>
123 constexpr char_type & assign_rank_to(decltype(to_rank(char_type{})) const rank, char_type & chr) noexcept
124 {
125  return chr = rank;
126 }
128 
129 } // namespace seqan3::custom
constexpr char_type to_char(char_type const chr) noexcept
Converting char to char is no-op (it will just return the value you pass in).
Definition: char.hpp:79
Provides metaprogramming utilities for integer types.
The Concepts library.
constexpr auto to_rank(char_type const chr) noexcept
Convert char to rank by casting to an unsigned integral type of same size.
Definition: char.hpp:93
Definition: aligned_sequence_concept.hpp:35
constexpr char_type & assign_rank_to(decltype(to_rank(char_type{})) const rank, char_type &chr) noexcept
Assigning a rank to a char is the same as assigning it a numeric value.
Definition: char.hpp:123
constexpr auto alphabet_size(char_type const &chr) noexcept
Return the number of values the char type can take.
Definition: char.hpp:65
constexpr char_type & assign_char_to(char_type const chr2, char_type &chr) noexcept
Assign a char to the char type (same as calling =).
Definition: char.hpp:108
A namespace for third party and standard library specialisations of SeqAn customisation points...
Definition: char.hpp:47
The concept std::Same<T, U> is satisfied if and only if T and U denote the same type.