30template <
typename t,
size_t extent = std::dynamic_extent>
35template <
typename t,
size_t extent>
41template <
typename other_t,
typename... alternative_types>
45 other_t>)&&(!(std::same_as<other_t, alternative_types> || ...))
49template <
typename lhs_t,
typename rhs_t,
bool lhs_rhs_switched,
typename... alternative_types>
54 variant_general_guard<rhs_t, alternative_types...>)&&!(lhs_rhs_switched
55 && is_type_specialisation_of_v<rhs_t,
122template <
typename... alternative_types>
123 requires (detail::writable_constexpr_alphabet<alternative_types> && ...) && (std::regular<alternative_types> && ...)
124 && (
sizeof...(alternative_types) >= 2)
127 (static_cast<size_t>(alphabet_size<alternative_types>) + ...),
133 (
static_cast<size_t>(alphabet_size<alternative_types>) + ...),
136 static_assert((std::is_same_v<alphabet_char_t<alternative_types>,
char> && ...),
137 "The alphabet_variant is currently only tested for alphabets with char_type char. "
138 "Contact us on GitHub if you have a different use case: https://github.com/seqan/seqan3 .");
146 static_assert(((seqan3::list_traits::count<alternative_types, alternatives> == 1) && ... &&
true),
147 "All types in a alphabet_variant must be distinct.");
180 template <
typename alternative_t>
204 template <typename alternative_t>
205 requires (!
std::same_as<alternative_t,
alphabet_variant>) && (!detail::is_span<alternative_t>::value)
207 && (!list_traits::contains<
209 detail::transformation_trait_or_t<detail::recursive_required_types<alternative_t>,
type_list<>>>)
234 template <
typename indirect_alternative_t>
238 detail::variant_general_guard<indirect_alternative_t, alternative_types...>>
243 constexpr auto alternative_position =
244 seqan3::list_traits::find_if<alternative_predicate::template invoke, alternatives>;
265 template <
typename indirect_alternative_t>
267 (!(detail::instantiate_if_v<detail::lazy<std::is_convertible, indirect_alternative_t, alternative_types>,
271 detail::variant_general_guard<indirect_alternative_t, alternative_types...>>
276 constexpr auto alternative_position =
277 seqan3::list_traits::find_if<alternative_predicate::template invoke, alternatives>;
293 template <
typename indirect_alternative_t>
299 constexpr auto alternative_position =
300 seqan3::list_traits::find_if<alternative_predicate::template invoke, alternatives>;
302 alternative_t alternative{};
318 template <
size_t index>
321 static_assert(index <
alphabet_size,
"The alphabet_variant contains less alternatives than you are checking.");
331 template <
size_t index>
334 return convert_impl<index, true>();
342 template <
size_t index>
345 return convert_impl<index, false>();
357 template <
typename alternative_t>
361 constexpr size_t index = seqan3::list_traits::find<alternative_t, alternatives>;
362 return holds_alternative<index>();
371 template <
typename alternative_t>
375 constexpr size_t index = seqan3::list_traits::find<alternative_t, alternatives>;
376 return convert_impl<index, true>();
384 template <
typename alternative_t>
388 constexpr size_t index = seqan3::list_traits::find<alternative_t, alternatives>;
389 return convert_impl<index, false>();
415 template <
typename alphabet_variant_t,
typename indirect_alternative_type>
418 indirect_alternative_type,
420 alternative_types...>)
421 friend constexpr bool operator==(alphabet_variant_t
const lhs, indirect_alternative_type
const rhs)
noexcept
424 constexpr auto alternative_position =
425 seqan3::list_traits::find_if<alternative_predicate::template invoke, alternatives>;
427 return lhs.template holds_alternative<alternative_t>()
428 && (lhs.template convert_unsafely_to<alternative_t>() == rhs);
432 template <
typename alphabet_variant_t,
typename indirect_alternative_type>
433 friend constexpr auto
438 return !(lhs == rhs);
442 template <
typename alphabet_variant_t,
typename indirect_alternative_type,
typename =
void>
445 indirect_alternative_type,
447 alternative_types...>)
448 friend constexpr bool operator==(indirect_alternative_type
const lhs, alphabet_variant_t
const rhs)
noexcept
454 template <
typename alphabet_variant_t,
typename indirect_alternative_type,
typename =
void>
455 friend constexpr auto operator!=(indirect_alternative_type
const lhs, alphabet_variant_t
const rhs)
noexcept
481 template <
size_t index,
bool throws>
484 static_assert(index <
alphabet_size,
"The alphabet_variant contains less alternatives than you are checking.");
487 if constexpr (
throws)
489 if (!holds_alternative<index>())
503 template <
size_t index,
typename alternative_t>
504 requires (is_alternative<alternative_t>())
515 template <
typename alternative_t>
516 requires (is_alternative<alternative_t>())
519 constexpr size_t index = seqan3::list_traits::find<alternative_t, alternatives>;
520 return rank_by_index_<index>(alternative);
557 constexpr size_t N =
sizeof...(alternative_types) + 1;
561 for (
size_t i = 1u; i < N; ++i)
562 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;
598 constexpr size_t alternative_size =
sizeof...(alternative_types);
599 constexpr size_t table_size = detail::size_in_values_v<char_type>;
604 for (
size_t i = 0u; i < table_size; ++i)
610 auto found_it =
std::find(valid_chars.begin(), valid_chars.end(),
true);
611 lookup_table[i] = found_it - valid_chars.begin();
622 constexpr size_t alternative_size =
sizeof...(alternative_types);
623 constexpr size_t table_size = detail::size_in_values_v<char_type>;
627 for (
size_t i = 0u; i < table_size; ++i)
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
rank_type rank
The value of the alphabet letter is stored as the rank.
Definition alphabet_base.hpp:258
A combined alphabet that can hold values of either of its alternatives..
Definition alphabet_variant.hpp:129
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:468
static constexpr bool is_alternative() noexcept
Returns true if alternative_t is one of the given alternative types.
Definition alphabet_variant.hpp:181
constexpr alternative_t convert_to() const
Convert to the specified alphabet (throws if holds_alternative() would be false).
Definition alphabet_variant.hpp:372
static constexpr rank_type rank_by_type_(alternative_t const &alternative) noexcept
Converts an object of one of the given alternatives into the internal representation.
Definition alphabet_variant.hpp:517
static constexpr std::array< rank_type, sizeof...(alternative_types)+1 > partial_sum_sizes
Compile-time generated lookup table which contains the partial sum up to the position of each alterna...
Definition alphabet_variant.hpp:555
constexpr bool holds_alternative() const noexcept
Whether the variant alphabet currently holds a value of the given alternative.
Definition alphabet_variant.hpp:319
constexpr alphabet_variant(indirect_alternative_t const rhs) noexcept
Constructor for arguments implicitly convertible to an alternative.
Definition alphabet_variant.hpp:240
constexpr auto convert_impl() const noexcept(!throws) -> seqan3::list_traits::at< index, alternatives >
Implementation function for convert_to() and convert_unsafely_to().
Definition alphabet_variant.hpp:482
static constexpr rank_type char_to_rank(char_type const chr)
Compile-time generated lookup table which maps the char to rank.
Definition alphabet_variant.hpp:540
constexpr bool holds_alternative() const noexcept
Whether the variant alphabet currently holds a value of the given alternative.
Definition alphabet_variant.hpp:358
constexpr alphabet_variant(indirect_alternative_t const rhs) noexcept
Constructor for arguments explicitly (but not implicitly) convertible to an alternative.
Definition alphabet_variant.hpp:273
friend base_t
Befriend the base type.
Definition alphabet_variant.hpp:141
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:385
friend constexpr auto operator!=(alphabet_variant_t const lhs, indirect_alternative_type const rhs) noexcept -> std::enable_if_t< detail::variant_comparison_guard< alphabet_variant_t, indirect_alternative_type, false, alternative_types... >, bool >
(In-)Equality comparison against types comparable with alternatives but not convertible to the varian...
Definition alphabet_variant.hpp:434
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:332
static constexpr rank_type rank_by_index_(alternative_t const &alternative) noexcept
Converts an object of one of the given alternatives into the internal representation.
Definition alphabet_variant.hpp:505
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:421
constexpr alphabet_variant() noexcept=default
Defaulted.
static constexpr char_type rank_to_char(rank_type const rank)
Compile-time generated lookup table which maps the rank to char.
Definition alphabet_variant.hpp:529
constexpr auto convert_unsafely_to() const noexcept
Convert to the specified alphabet (undefined behaviour if holds_alternative() would be false).
Definition alphabet_variant.hpp:343
static constexpr auto first_valid_char_table
Compile-time generated lookup table which maps the char to the index of the first alphabet that fulfi...
Definition alphabet_variant.hpp:596
friend constexpr auto operator!=(indirect_alternative_type const lhs, alphabet_variant_t const rhs) noexcept -> std::enable_if_t< detail::variant_comparison_guard< alphabet_variant_t, indirect_alternative_type, true, alternative_types... >, bool >
(In-)Equality comparison against types comparable with alternatives but not convertible to the varian...
Definition alphabet_variant.hpp:455
static constexpr std::array< char_type, alphabet_size > rank_to_char_table
Compile-time generated lookup table which maps the rank to char.
Definition alphabet_variant.hpp:570
type_list< alternative_types... > seqan3_required_types
Expose the alternative types to concept checks in metaprogramming.
Definition alphabet_variant.hpp:163
static constexpr std::array< rank_type, detail::size_in_values_v< char_type > > char_to_rank_table
Compile-time generated lookup table which maps the char to rank.
Definition alphabet_variant.hpp:620
list_traits::concat< seqan3_required_types, detail::transformation_trait_or_t< detail::recursive_required_types< alternative_types >, type_list<> >... > seqan3_recursive_required_types
Expose the recursive alternative types to concept checks in metaprogramming.
Definition alphabet_variant.hpp:171
constexpr auto assign_char_to
Assign a character to an alphabet object.
Definition alphabet/concept.hpp:521
constexpr auto to_char
Return the char representation of an alphabet object.
Definition alphabet/concept.hpp:383
constexpr auto assign_rank_to
Assign a rank to an alphabet object.
Definition alphabet/concept.hpp:290
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
typename transformation_trait_or< type_t, default_t >::type transformation_trait_or_t
Helper type of seqan3::detail::transformation_trait_or (transformation_trait shortcut).
Definition transformation_trait_or.hpp:48
Resolves to std::is_assignable_v<t>.
Provides lazy template instantiation traits.
The internal SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
constexpr bool variant_general_guard
Prevents wrong instantiations of std::alphabet_variant's constructors.
Definition alphabet_variant.hpp:42
constexpr bool variant_comparison_guard
Prevents wrong instantiations of std::alphabet_variant's comparison operators.
Definition alphabet_variant.hpp:50
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
SeqAn specific customisations in the standard namespace.
'Callable' helper class that is invokable by meta::invoke.Returns a std::true_type if the type is ass...
Definition alphabet/composite/detail.hpp:151
'Callable' helper class that is invokable by meta::invoke.Returns a std::true_type if the type is con...
Definition alphabet/composite/detail.hpp:127
'Callable' helper class that is invokable by meta::invoke.Returns a std::true_type if the T is implic...
Definition alphabet/composite/detail.hpp:139
Helper to determine whether a type is a std::span.
Definition alphabet_variant.hpp:32
An empty type whose only purpose is to hold an uninstantiated template plus its arguments.
Definition lazy_conditional.hpp:30
'Callable' helper class that is invokable by meta::invoke.Returns a std::true_type if the type is wea...
Definition alphabet/composite/detail.hpp:163
Type that contains multiple types.
Definition type_list.hpp:26
Provides traits for seqan3::type_list.