SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
uint.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
23#pragma once
24
27
28namespace seqan3::detail
29{
33template <typename type>
34constexpr bool is_uint_adaptation_v =
35 std::same_as<type, uint8_t> || std::same_as<type, uint16_t> || std::same_as<type, uint32_t>;
36} // namespace seqan3::detail
37
38namespace seqan3::custom
39{
40
47template <typename uint_type>
48 requires seqan3::detail::is_uint_adaptation_v<uint_type>
49struct alphabet<uint_type>
50{
55 static constexpr auto alphabet_size =
56 detail::min_viable_uint_t<detail::size_in_values_v<uint_type>>{detail::size_in_values_v<uint_type>};
57
64 static constexpr auto to_char(uint_type const uint_v) noexcept
65 {
66 if constexpr (std::same_as<uint_type, uint8_t>)
67 return static_cast<char>(uint_v);
68 else if constexpr (std::same_as<uint_type, uint16_t>)
69 return static_cast<char16_t>(uint_v);
70 else
71 return static_cast<char32_t>(uint_v);
72 }
73
80 static constexpr uint_type to_rank(uint_type const uint_v) noexcept
81 {
82 return uint_v;
83 }
84
92 static constexpr uint_type & assign_char_to(decltype(to_char(uint_type{})) const chr, uint_type & uint_v) noexcept
93 {
94 return uint_v = chr;
95 }
96
104 static constexpr uint_type & assign_rank_to(uint_type const uint2_v, uint_type & uint_v) noexcept
105 {
106 return uint_v = uint2_v;
107 }
108};
109
110} // namespace seqan3::custom
Core alphabet concept and free function/type trait wrappers.
constexpr auto to_char
Return the char representation of an alphabet object.
Definition alphabet/concept.hpp:383
constexpr auto alphabet_size
A type trait that holds the size of a (semi-)alphabet.
Definition alphabet/concept.hpp:846
Provides metaprogramming utilities for integer types.
A namespace for third party and standard library specialisations of SeqAn customisation points.
Definition char.hpp:39
static constexpr uint_type & assign_rank_to(uint_type const uint2_v, uint_type &uint_v) noexcept
Assign a rank to the uint (same as calling =).
Definition uint.hpp:104
static constexpr auto to_char(uint_type const uint_v) noexcept
Converting uint to char casts to a character type of same size.
Definition uint.hpp:64
static constexpr uint_type to_rank(uint_type const uint_v) noexcept
Converting uint to rank is a no-op (it will just return the value you pass in).
Definition uint.hpp:80
static constexpr uint_type & assign_char_to(decltype(to_char(uint_type{})) const chr, uint_type &uint_v) noexcept
Assign from a character type via implicit or explicit cast.
Definition uint.hpp:92
A type that can be specialised to provide customisation point implementations so that third party typ...
Definition alphabet/concept.hpp:46
Hide me