SeqAn3  3.0.0
The Modern C++ library for sequence analysis.
uint.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 type2 = std::remove_reference_t<type>>
40 constexpr bool is_uint_adaptation_v = std::Same<type2, uint8_t> ||
44 } // namespace seqan3::detail
45 
46 namespace seqan3::custom
47 {
48 
60 template <typename uint_type>
62  requires ::seqan3::detail::is_uint_adaptation_v<uint_type>
64 constexpr auto alphabet_size(uint_type const & SEQAN3_DOXYGEN_ONLY(intgr)) noexcept
65 {
66  return detail::min_viable_uint_t<detail::size_in_values_v<uint_type>>{detail::size_in_values_v<uint_type>};
67 }
68 
74 template <typename uint_type>
76  requires detail::is_uint_adaptation_v<uint_type>
78 constexpr auto to_char(uint_type const intgr) noexcept
79 {
80  if constexpr (std::Same<uint_type, uint8_t>)
81  return static_cast<char>(intgr);
82  else if constexpr (std::Same<uint_type, uint16_t>)
83  return static_cast<char16_t>(intgr);
84  else
85  return static_cast<char32_t>(intgr);
86 }
87 
93 template <typename uint_type>
95  requires detail::is_uint_adaptation_v<uint_type>
97 constexpr uint_type to_rank(uint_type const intgr) noexcept
98 {
99  return intgr;
100 }
101 
108 template <typename uint_type>
110  requires detail::is_uint_adaptation_v<uint_type>
112 constexpr uint_type & assign_char_to(decltype(to_char(uint_type{})) const chr, uint_type & intgr) noexcept
113 {
114  return intgr = chr;
115 }
116 
123 template <typename uint_type>
125  requires detail::is_uint_adaptation_v<uint_type>
127 constexpr uint_type & assign_rank_to(uint_type const intgr2, uint_type & intgr) noexcept
128 {
129  return intgr = intgr2;
130 }
131 
133 } // 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.