26namespace seqan3::detail
30template <
typename t,
size_t extent = std::dynamic_extent>
35template <
typename t,
size_t extent>
41template <
typename other_t,
typename... alternative_types>
42inline constexpr bool variant_general_guard =
43 (!std::same_as<other_t, alphabet_variant<alternative_types...>>)
45 && (!(std::same_as<other_t, alternative_types> || ...))
46 && (!
list_traits::contains<alphabet_variant<alternative_types...>, recursive_required_types_t<other_t>>);
49template <
typename lhs_t,
typename rhs_t,
bool lhs_rhs_switched,
typename... alternative_types>
50inline constexpr bool variant_comparison_guard =
51 (instantiate_if_v<lazy<weakly_equality_comparable_with_trait, rhs_t, alternative_types>,
52 (std::same_as<lhs_t, alphabet_variant<alternative_types...>>)
53 && (variant_general_guard<rhs_t, alternative_types...>)
54 && !(lhs_rhs_switched && is_type_specialisation_of_v<rhs_t, alphabet_variant>)>
120template <
typename... alternative_types>
121 requires (detail::writable_constexpr_alphabet<alternative_types> && ...) && (std::regular<alternative_types> && ...)
122 && (
sizeof...(alternative_types) >= 2)
125 (static_cast<size_t>(alphabet_size<alternative_types>) + ...),
134 static_assert((std::is_same_v<alphabet_char_t<alternative_types>,
char> && ...),
135 "The alphabet_variant is currently only tested for alphabets with char_type char. "
136 "Contact us on GitHub if you have a different use case: https://github.com/seqan/seqan3 .");
144 static_assert(((seqan3::list_traits::count<alternative_types, alternatives> == 1) && ... &&
true),
145 "All types in a alphabet_variant must be distinct.");
169 detail::transformation_trait_or_t<detail::recursive_required_types<alternative_types>,
type_list<>>...>;
178 template <
typename alternative_t>
205 && (!list_traits::contains<
232 template <
typename indirect_alternative_t>
233 requires (!detail::is_span<indirect_alternative_t>::value)
235 detail::instantiate_if_v<detail::lazy<std::is_convertible, indirect_alternative_t, alternative_types>,
236 detail::variant_general_guard<indirect_alternative_t, alternative_types...>>
242 seqan3::list_traits::find_if<alternative_predicate::template invoke, alternatives>;
263 template <
typename indirect_alternative_t>
265 (!(detail::instantiate_if_v<detail::lazy<std::is_convertible, indirect_alternative_t, alternative_types>,
268 && (detail::instantiate_if_v<detail::lazy<std::is_constructible, alternative_types, indirect_alternative_t>,
269 detail::variant_general_guard<indirect_alternative_t, alternative_types...>>
275 seqan3::list_traits::find_if<alternative_predicate::template invoke, alternatives>;
291 template <
typename indirect_alternative_t>
298 seqan3::list_traits::find_if<alternative_predicate::template invoke, alternatives>;
316 template <
size_t index>
319 static_assert(index <
alphabet_size,
"The alphabet_variant contains less alternatives than you are checking.");
320 return (
to_rank() >= partial_sum_sizes[index]) && (
to_rank() < partial_sum_sizes[index + 1]);
329 template <
size_t index>
340 template <
size_t index>
355 template <
typename alternative_t>
359 constexpr size_t index = seqan3::list_traits::find<alternative_t, alternatives>;
369 template <
typename alternative_t>
373 constexpr size_t index = seqan3::list_traits::find<alternative_t, alternatives>;
382 template <
typename alternative_t>
386 constexpr size_t index = seqan3::list_traits::find<alternative_t, alternatives>;
413 template <
typename alphabet_variant_t,
typename indirect_alternative_type>
414 requires (!detail::is_span<alphabet_variant_t>::value)
423 seqan3::list_traits::find_if<alternative_predicate::template invoke, alternatives>;
430 template <
typename alphabet_variant_t,
typename indirect_alternative_type>
431 requires (!detail::is_span<alphabet_variant_t>::value)
442 template <
typename alphabet_variant_t,
typename indirect_alternative_type,
typename =
void>
443 requires (!detail::is_span<alphabet_variant_t>::value)
454 template <
typename alphabet_variant_t,
typename indirect_alternative_type,
typename =
void>
455 requires (!detail::is_span<alphabet_variant_t>::value)
483 template <
size_t index,
bool throws>
486 static_assert(index <
alphabet_size,
"The alphabet_variant contains less alternatives than you are checking.");
489 if constexpr (
throws)
505 template <
size_t index,
typename alternative_t>
506 requires (is_alternative<alternative_t>())
507 static constexpr rank_type rank_by_index_(alternative_t
const & alternative)
noexcept
517 template <
typename alternative_t>
518 requires (is_alternative<alternative_t>())
519 static constexpr rank_type rank_by_type_(alternative_t
const & alternative)
noexcept
521 constexpr size_t index = seqan3::list_traits::find<alternative_t, alternatives>;
522 return rank_by_index_<index>(alternative);
533 return rank_to_char_table[rank];
545 return char_to_rank_table[
static_cast<index_t
>(chr)];
555 static constexpr std::array<
rank_type,
sizeof...(alternative_types) + 1> partial_sum_sizes{
558 constexpr size_t N =
sizeof...(alternative_types) + 1;
562 for (
size_t i = 1u; i < N; ++i)
563 partial_sum[i] += partial_sum[i - 1];
572 auto assign_value_to_char = [](
auto alternative,
auto & value_to_char,
auto & value)
constexpr
574 using alternative_t =
std::decay_t<
decltype(alternative)>;
575 for (
size_t i = 0u; i < seqan3::alphabet_size<alternative_t>; ++i, ++value)
586 ((assign_value_to_char(alternative_types{}, value_to_char, value)), ...);
588 return value_to_char;
594 static constexpr auto first_valid_char_table{
597 constexpr size_t alternative_size =
sizeof...(alternative_types);
598 constexpr size_t table_size = detail::size_in_values_v<char_type>;
599 using first_alphabet_t = detail::min_viable_uint_t<alternative_size>;
603 for (
size_t i = 0u; i < table_size; ++i)
609 auto found_it =
std::find(valid_chars.begin(), valid_chars.end(),
true);
610 lookup_table[i] = found_it - valid_chars.begin();
620 constexpr size_t alternative_size =
sizeof...(alternative_types);
621 constexpr size_t table_size = detail::size_in_values_v<char_type>;
625 for (
size_t i = 0u; i < table_size; ++i)
633 char_to_rank[i] = first_valid_char_table[i] < alternative_size ? ranks[first_valid_char_table[i]] : 0;
Provides implementation detail for seqan3::alphabet_variant and seqan3::alphabet_tuple_base.
Provides seqan3::alphabet_base.
A CRTP-base that makes defining a custom alphabet easier.
Definition alphabet_base.hpp:54
constexpr rank_type to_rank() const noexcept
Return the letter's numeric value (rank in the alphabet).
Definition alphabet_base.hpp:134
detail::min_viable_uint_t< size - 1 > rank_type
The type of the alphabet when represented as a number (e.g. via to_rank()).
Definition alphabet_base.hpp:77
static constexpr detail::min_viable_uint_t< size > alphabet_size
The size of the alphabet, i.e. the number of different values it can take.
Definition alphabet_base.hpp:196
constexpr char_type to_char() const noexcept
Return the letter as a character of char_type.
Definition alphabet_base.hpp:112
std::conditional_t< std::same_as< char, void >, char, char > char_type
The char representation; conditional needed to make semi alphabet definitions legal.
Definition alphabet_base.hpp:69
constexpr alphabet_variant< alternative_types... > & assign_rank(rank_type const c) noexcept
Assign from a numeric value.
Definition alphabet_base.hpp:184
A combined alphabet that can hold values of either of its alternatives..
Definition alphabet_variant.hpp:127
static constexpr bool char_is_valid(char_type const chr) noexcept
Validate whether a character is valid in the combined alphabet.
Definition alphabet_variant.hpp:470
static constexpr bool is_alternative() noexcept
Returns true if alternative_t is one of the given alternative types.
Definition alphabet_variant.hpp:179
constexpr alternative_t convert_to() const
Convert to the specified alphabet (throws if holds_alternative() would be false).
Definition alphabet_variant.hpp:370
friend constexpr bool operator!=(indirect_alternative_type const lhs, alphabet_variant_t const rhs) noexcept
(In-)Equality comparison against types comparable with alternatives but not convertible to the varian...
Definition alphabet_variant.hpp:460
constexpr bool holds_alternative() const noexcept
Whether the variant alphabet currently holds a value of the given alternative.
Definition alphabet_variant.hpp:317
constexpr alphabet_variant(indirect_alternative_t const rhs) noexcept
Constructor for arguments implicitly convertible to an alternative.
Definition alphabet_variant.hpp:238
constexpr bool holds_alternative() const noexcept
Whether the variant alphabet currently holds a value of the given alternative.
Definition alphabet_variant.hpp:356
constexpr alphabet_variant(indirect_alternative_t const rhs) noexcept
Constructor for arguments explicitly (but not implicitly) convertible to an alternative.
Definition alphabet_variant.hpp:271
constexpr alternative_t convert_unsafely_to() const noexcept
Convert to the specified alphabet (undefined behaviour if holds_alternative() would be false).
Definition alphabet_variant.hpp:383
friend constexpr bool operator!=(alphabet_variant_t const lhs, indirect_alternative_type const rhs) noexcept
(In-)Equality comparison against types comparable with alternatives but not convertible to the varian...
Definition alphabet_variant.hpp:436
friend constexpr bool operator==(indirect_alternative_type const lhs, alphabet_variant_t const rhs) noexcept
(In-)Equality comparison against types comparable with alternatives but not convertible to the varian...
Definition alphabet_variant.hpp:448
constexpr auto convert_to() const
Convert to the specified alphabet (throws if holds_alternative() would be false).
Definition alphabet_variant.hpp:330
friend constexpr bool operator==(alphabet_variant_t const lhs, indirect_alternative_type const rhs) noexcept
(In-)Equality comparison against types comparable with alternatives but not convertible to the varian...
Definition alphabet_variant.hpp:419
constexpr alphabet_variant() noexcept=default
Defaulted.
constexpr auto convert_unsafely_to() const noexcept
Convert to the specified alphabet (undefined behaviour if holds_alternative() would be false).
Definition alphabet_variant.hpp:341
A "pretty printer" for most SeqAn data structures and related types.
Definition debug_stream_type.hpp:79
constexpr auto assign_char_to
Assign a character to an alphabet object.
Definition alphabet/concept.hpp:517
constexpr auto to_char
Return the char representation of an alphabet object.
Definition alphabet/concept.hpp:381
constexpr auto assign_rank_to
Assign a rank to an alphabet object.
Definition alphabet/concept.hpp:288
constexpr auto to_rank
Return the rank representation of a (semi-)alphabet object.
Definition alphabet/concept.hpp:152
decltype(detail::concat(lists_t{}...)) concat
Join two seqan3::type_list s into one.
Definition type_list/traits.hpp:339
constexpr bool contains
Whether a type occurs in a type list or not.
Definition type_list/traits.hpp:249
typename decltype(detail::at< idx >(list_t{}))::type at
Return the type at given index from the type list.
Definition type_list/traits.hpp:276
constexpr bool contains
Whether a type occurs in a pack or not.
Definition type_pack/traits.hpp:220
Provides lazy template instantiation traits.
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
SeqAn specific customisations in the standard namespace.
Type that contains multiple types.
Definition type_list.hpp:26
Provides traits for seqan3::type_list.