SeqAn3 3.2.0
The Modern C++ library for sequence analysis.
uint.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_uint_adaptation_v =
38 std::same_as<type, uint8_t> || std::same_as<type, uint16_t> || std::same_as<type, uint32_t>;
39} // namespace seqan3::detail
40
41namespace seqan3::custom
42{
43
50template <typename uint_type>
51 requires seqan3::detail::is_uint_adaptation_v<uint_type>
52struct alphabet<uint_type>
53{
58 static constexpr auto alphabet_size =
59 detail::min_viable_uint_t<detail::size_in_values_v<uint_type>>{detail::size_in_values_v<uint_type>};
60
67 static constexpr auto to_char(uint_type const uint_v) noexcept
68 {
69 if constexpr (std::same_as<uint_type, uint8_t>)
70 return static_cast<char>(uint_v);
71 else if constexpr (std::same_as<uint_type, uint16_t>)
72 return static_cast<char16_t>(uint_v);
73 else
74 return static_cast<char32_t>(uint_v);
75 }
76
83 static constexpr uint_type to_rank(uint_type const uint_v) noexcept
84 {
85 return uint_v;
86 }
87
95 static constexpr uint_type & assign_char_to(decltype(to_char(uint_type{})) const chr, uint_type & uint_v) noexcept
96 {
97 return uint_v = chr;
98 }
99
107 static constexpr uint_type & assign_rank_to(uint_type const uint2_v, uint_type & uint_v) noexcept
108 {
109 return uint_v = uint2_v;
110 }
111};
112
113} // 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: concept.hpp:386
constexpr auto alphabet_size
A type trait that holds the size of a (semi-)alphabet.
Definition: concept.hpp:849
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 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:107
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:67
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:83
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:95
A type that can be specialised to provide customisation point implementations so that third party typ...
Definition: concept.hpp:49