SeqAn3 3.2.0
The Modern C++ library for sequence analysis.
char.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2006-2022, Knut Reinert & Freie Universität Berlin
3// Copyright (c) 2016-2022, 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
30
31namespace seqan3::detail
32{
36template <typename type>
37constexpr bool is_char_adaptation_v = std::same_as<type, char> || std::same_as<type, char16_t>
38 || std::same_as<type, char32_t> || std::same_as<type, wchar_t>;
39} // namespace seqan3::detail
40
42{
43
50template <typename char_type>
51 requires detail::is_char_adaptation_v<char_type>
52struct alphabet<char_type>
53{
58 static constexpr auto alphabet_size =
59 detail::min_viable_uint_t<detail::size_in_values_v<char_type>>{detail::size_in_values_v<char_type>};
60
67 static constexpr char_type to_char(char_type const chr) noexcept
68 {
69 return chr;
70 }
71
78 static constexpr auto to_rank(char_type const chr) noexcept
79 {
80 return static_cast<detail::min_viable_uint_t<alphabet_size - 1>>(chr);
81 }
82
90 static constexpr char_type & assign_char_to(char_type const chr2, char_type & chr) noexcept
91 {
92 return chr = chr2;
93 }
94
102 static constexpr char_type & assign_rank_to(decltype(alphabet::to_rank(char_type{})) const rank,
103 char_type & chr) noexcept
104 {
105 return chr = rank;
106 }
107};
108
109} // namespace seqan3::custom
Core alphabet concept and free function/type trait wrappers.
constexpr auto alphabet_size
A type trait that holds the size of a (semi-)alphabet.
Definition: concept.hpp:849
constexpr auto to_rank
Return the rank representation of a (semi-)alphabet object.
Definition: concept.hpp:155
Provides metaprogramming utilities for integer types.
A namespace for third party and standard library specialisations of SeqAn customisation points.
Definition: char.hpp:42
static 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:78
static 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:90
static 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:67
static constexpr char_type & assign_rank_to(decltype(alphabet::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:102
A type that can be specialised to provide customisation point implementations so that third party typ...
Definition: concept.hpp:49