A combined alphabet that can hold values of either of its alternatives. More...
#include <seqan3/alphabet/composite/alphabet_variant.hpp>
Public Member Functions | |
Constructors, destructor and assignment | |
constexpr | alphabet_variant () noexcept=default |
Defaulted. | |
constexpr | alphabet_variant (alphabet_variant const &) noexcept=default |
Defaulted. | |
constexpr | alphabet_variant (alphabet_variant &&) noexcept=default |
Defaulted. | |
constexpr alphabet_variant & | operator= (alphabet_variant const &) noexcept=default |
Defaulted. | |
constexpr alphabet_variant & | operator= (alphabet_variant &&) noexcept=default |
Defaulted. | |
~alphabet_variant () noexcept=default | |
Defaulted. | |
template<typename alternative_t > | |
constexpr | alphabet_variant (alternative_t const alternative) noexcept |
Construction via the value of an alternative. More... | |
template<typename indirect_alternative_t > | |
constexpr | alphabet_variant (indirect_alternative_t const rhs) noexcept |
Constructor for arguments implicitly convertible to an alternative. More... | |
template<typename indirect_alternative_t > | |
constexpr | alphabet_variant (indirect_alternative_t const rhs) noexcept |
Constructor for arguments explicitly (but not implicitly) convertible to an alternative. More... | |
template<typename indirect_alternative_t > | |
constexpr alphabet_variant & | operator= (indirect_alternative_t const &rhs) noexcept |
Assignment for arguments assignable to an alternative. More... | |
Conversion (by index) | |
template<size_t index> | |
constexpr bool | is_alternative () const noexcept |
Whether the variant alphabet currently holds a value of the given alternative. More... | |
template<size_t index> | |
constexpr auto | convert_to () const |
Convert to the specified alphabet (throws if is_alternative() would be false). More... | |
template<size_t index> | |
constexpr auto | convert_unsafely_to () const noexcept |
Convert to the specified alphabet (undefined behaviour if is_alternative() would be false). More... | |
Conversion (by type) | |
template<typename alternative_t > | |
constexpr bool | is_alternative () const noexcept |
Whether the variant alphabet currently holds a value of the given alternative. More... | |
template<typename alternative_t > | |
constexpr alternative_t | convert_to () const |
Convert to the specified alphabet (throws if is_alternative() would be false). More... | |
template<typename alternative_t > | |
constexpr alternative_t | convert_unsafely_to () const noexcept |
Convert to the specified alphabet (undefined behaviour if is_alternative() would be false). More... | |
Read functions | |
constexpr char_type | to_char () const noexcept |
Return the letter as a character of char_type. More... | |
constexpr rank_type | to_rank () const noexcept |
Return the letter's numeric value (rank in the alphabet). More... | |
Write functions | |
constexpr alphabet_variant< alternative_types... > & | assign_char (char_type const c) noexcept |
Assign from a character, implicitly converts invalid characters. More... | |
constexpr alphabet_variant< alternative_types... > & | assign_rank (rank_type const c) noexcept |
Assign from a numeric value. More... | |
Static Public Member Functions | |
static constexpr bool | char_is_valid (char_type const chr) noexcept |
Validate whether a character is valid in the combined alphabet. | |
template<typename alternative_t > | |
static constexpr bool | holds_alternative () noexcept |
Returns true if alternative_t is one of the given alternative types. More... | |
Static Public Attributes | |
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. More... | |
Protected Types | |
Member types | |
using | char_type = std::conditional_t< std::same_as< char, void >, char, char > |
The char representation; conditional needed to make semi alphabet definitions legal. More... | |
using | rank_type = detail::min_viable_uint_t< size - 1 > |
The type of the alphabet when represented as a number (e.g. via to_rank()). More... | |
Private Types | |
using | alternatives = meta::list< alternative_types... > |
A meta::list of the types of each alternative in the composite. | |
using | base_t = alphabet_base< alphabet_variant< alternative_types... >,(static_cast< size_t >(alphabet_size< alternative_types >)+...), char > |
The base type. | |
using | seqan3_recursive_required_types = list_traits::concat< seqan3_required_types, detail::transformation_trait_or_t< detail::recursive_required_types< alternative_types >, type_list<> >... > |
Expose the recursive alternative types to concept checks in metaprogramming. | |
using | seqan3_required_types = type_list< alternative_types... > |
Expose the alternative types to concept checks in metaprogramming. | |
Private Member Functions | |
template<size_t index, bool throws> | |
constexpr auto | convert_impl () const noexcept(!throws) -> meta::at_c< alternatives, index > |
Implementation function for convert_to() and convert_unsafely_to(). More... | |
Static Private Member Functions | |
template<size_t index, typename alternative_t > | |
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. More... | |
template<typename alternative_t > | |
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. More... | |
Private Attributes | |
friend | base_t |
Befriend the base type. | |
rank_type | rank |
The value of the alphabet letter is stored as the rank. | |
Static Private Attributes | |
static constexpr std::array< rank_type, detail::size_in_values_v< char_type > > | char_to_rank |
Compile-time generated lookup table which maps the char to rank. More... | |
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 alternative. More... | |
static constexpr std::array< char_type, alphabet_size > | rank_to_char |
Compile-time generated lookup table which maps the rank to char. More... | |
Friends | |
Comparison operators (against indirect alternatives) | |
Defines comparison against types that are not subject to implicit construction/conversion but are comparable against alternatives, e.g. | |
template<typename alphabet_variant_t , typename indirect_alternative_type > | |
constexpr friend 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 variant. More... | |
template<typename alphabet_variant_t , typename indirect_alternative_type > | |
constexpr friend 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 variant. More... | |
template<typename alphabet_variant_t , typename indirect_alternative_type , typename = void> | |
constexpr friend 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 variant. More... | |
template<typename alphabet_variant_t , typename indirect_alternative_type , typename = void> | |
constexpr friend 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 variant. More... | |
Related Functions | |
(Note that these are not member functions.) | |
Generic serialisation functions for all seqan3::semialphabet | |
All types that satisfy seqan3::semialphabet can be serialised via Cereal. | |
template<cereal_output_archive archive_t, semialphabet alphabet_t> | |
alphabet_rank_t< alphabet_t > | save_minimal (archive_t const &, alphabet_t const &l) |
Save an alphabet letter to stream. More... | |
A combined alphabet that can hold values of either of its alternatives.
...alternative_types | Types of possible values (at least 2); all must model seqan3::detail::writable_constexpr_alphabet, std::regular and be unique. |
The alphabet_variant represents the union of two or more alternative alphabets (e.g. the four letter DNA alternative + the gap alternative). It behaves similar to a variant or std::variant, but it preserves the seqan3::alphabet.
Short description:
char
representation of an alphabet_variantPart of the seqan3::alphabet concept requires that the alphabet_variant provides a char representation in addition to the rank representation. For an object of seqan3::alphabet_variant, the to_char()
member function will always return the same character as if invoked on the respective alternative. In contrast, the assign_char()
member function might be ambiguous between the alternative alphabets in a variant.
For example, assigning a '!' to seqan3::dna15 resolves to an object of rank 8 with char representation 'N' while assigning '!' to seqan3::gap always resolves to rank 0, the gap symbol itself ('-'_gap). We tackle this ambiguousness by defaulting unknown characters to the representation of the first alternative (e.g. ‘alphabet_variant<dna15, gap>{}.assign_char(’!')resolves to rank 8, representing
N`_dna15).
On the other hand, two alternative alphabets might have the same char representation (e.g if you combine dna4 with dna5, 'A', 'C', 'G' and 'T' are ambiguous). We tackle this ambiguousness by always choosing the first valid char representation (e.g. ‘alphabet_variant<dna4, dna5>{}.assign_char('A’)resolves to rank 0, representing an
A`_dna4).
To explicitly assign via the character representation of a specific alphabet, assign to that type first and then assign to the variant, e.g.
|
protectedinherited |
The char representation; conditional needed to make semi alphabet definitions legal.
We need a return type for seqan3::alphabet_base::to_char and seqan3::alphabet_base::assign_char other than void to make these in-class definitions valid when char_t
is void.
|
protectedinherited |
The type of the alphabet when represented as a number (e.g. via to_rank()).
|
inlineconstexprnoexcept |
Construction via the value of an alternative.
alternative_t | One of the alternative types. |
alternative | The value of a alternative that should be assigned. |
|
inlineconstexprnoexcept |
Constructor for arguments implicitly convertible to an alternative.
indirect_alternative_t | A type that is implicitly convertible to an alternative type. |
rhs | The value that should be assigned. |
This constructor is preferred over the explicit version.
{}
considers implicit and explicit conversions.=
considers only implicit conversions (but that is sufficient here).
|
inlineexplicitconstexprnoexcept |
Constructor for arguments explicitly (but not implicitly) convertible to an alternative.
indirect_alternative_t | A type that is explicitly (but not implicitly) convertible to an alternative type. |
rhs | The value that should be assigned. |
{}
considers implicit and explicit conversions so this works.=
considers only implicit conversions so it does not work.
|
inlineconstexprnoexceptinherited |
Assign from a character, implicitly converts invalid characters.
c | The character to be assigned. |
Provides an implementation for seqan3::assign_char_to, required to model seqan3::alphabet.
Constant.
Guaranteed not to throw.
|
inlineconstexprnoexceptinherited |
Assign from a numeric value.
c | The rank to be assigned. |
Provides an implementation for seqan3::assign_rank_to, required to model seqan3::semialphabet.
Constant.
Guaranteed not to throw.
|
inlineconstexprprivatenoexcept |
Implementation function for convert_to() and convert_unsafely_to().
index | Index of the alternative to convert to. |
throws | Whether to perform checks (and throw) or not. |
|
inlineconstexpr |
Convert to the specified alphabet (throws if is_alternative() would be false).
index | Index of the alternative to check for. |
std::bad_variant_access | If the variant_alphabet currently holds the value of a different alternative. |
|
inlineconstexpr |
Convert to the specified alphabet (throws if is_alternative() would be false).
alternative_t | The type of the alternative that you wish to check for. |
std::bad_variant_access | If the variant_alphabet currently holds the value of a different alternative. |
|
inlineconstexprnoexcept |
Convert to the specified alphabet (undefined behaviour if is_alternative() would be false).
index | Index of the alternative to check for. |
|
inlineconstexprnoexcept |
Convert to the specified alphabet (undefined behaviour if is_alternative() would be false).
alternative_t | The type of the alternative that you wish to check for. |
|
inlinestaticconstexprnoexcept |
Returns true if alternative_t is one of the given alternative types.
alternative_t | The type to check. |
|
inlineconstexprnoexcept |
Whether the variant alphabet currently holds a value of the given alternative.
index | Index of the alternative to check for. |
|
inlineconstexprnoexcept |
Whether the variant alphabet currently holds a value of the given alternative.
alternative_t | The type of the alternative that you wish to check for. |
|
inlineconstexprnoexcept |
Assignment for arguments assignable to an alternative.
indirect_alternative_t | A type that one of the alternatives is assignable from. |
rhs | The value of an alternative. |
Most assignments happen through implicit conversion and the default assignment operator. This constructor is for the rest.
|
inlinestaticconstexprprivatenoexcept |
Converts an object of one of the given alternatives into the internal representation.
index | The position of alternative_t in the template pack alternative_types . |
alternative_t | One of the alternative types. |
alternative | The value of a alternative. |
|
inlinestaticconstexprprivatenoexcept |
Converts an object of one of the given alternatives into the internal representation.
Finds the index of alternative_t in the given types.
alternative_t | One of the alternative types. |
alternative | The value of a alternative. |
|
inlineconstexprnoexceptinherited |
Return the letter as a character of char_type.
Provides an implementation for seqan3::to_char, required to model seqan3::alphabet.
Constant.
Guaranteed not to throw.
|
inlineconstexprnoexceptinherited |
Return the letter's numeric value (rank in the alphabet).
Provides an implementation for seqan3::to_rank, required to model seqan3::semialphabet.
Constant.
Guaranteed not to throw.
|
friend |
(In-)Equality comparison against types comparable with alternatives but not convertible to the variant.
alphabet_variant_t | The type of the variant; given as template parameter to prevent conversion. |
indirect_alternative_type | Must be comparable with an alternative's type. |
lhs | Left-hand-side of comparison. |
rhs | Right-hand-side of comparison. |
true
or false
.To determine (in-)equality, it is first deduced which alternative the argument is comparable with. It is then checked if the variant currently is in that alternative's state and if yes whether the values compare to true
; else false
is returned.
|
friend |
(In-)Equality comparison against types comparable with alternatives but not convertible to the variant.
alphabet_variant_t | The type of the variant; given as template parameter to prevent conversion. |
indirect_alternative_type | Must be comparable with an alternative's type. |
lhs | Left-hand-side of comparison. |
rhs | Right-hand-side of comparison. |
true
or false
.To determine (in-)equality, it is first deduced which alternative the argument is comparable with. It is then checked if the variant currently is in that alternative's state and if yes whether the values compare to true
; else false
is returned.
|
friend |
(In-)Equality comparison against types comparable with alternatives but not convertible to the variant.
alphabet_variant_t | The type of the variant; given as template parameter to prevent conversion. |
indirect_alternative_type | Must be comparable with an alternative's type. |
lhs | Left-hand-side of comparison. |
rhs | Right-hand-side of comparison. |
true
or false
.To determine (in-)equality, it is first deduced which alternative the argument is comparable with. It is then checked if the variant currently is in that alternative's state and if yes whether the values compare to true
; else false
is returned.
|
friend |
(In-)Equality comparison against types comparable with alternatives but not convertible to the variant.
alphabet_variant_t | The type of the variant; given as template parameter to prevent conversion. |
indirect_alternative_type | Must be comparable with an alternative's type. |
lhs | Left-hand-side of comparison. |
rhs | Right-hand-side of comparison. |
true
or false
.To determine (in-)equality, it is first deduced which alternative the argument is comparable with. It is then checked if the variant currently is in that alternative's state and if yes whether the values compare to true
; else false
is returned.
|
related |
Save an alphabet letter to stream.
archive_t | Must satisfy seqan3::cereal_output_archive. |
alphabet_t | Type of l; must satisfy seqan3::semialphabet. |
l | The alphabet letter. |
Delegates to seqan3::to_rank.
|
staticconstexprinherited |
The size of the alphabet, i.e. the number of different values it can take.
|
staticconstexprprivate |
Compile-time generated lookup table which maps the char to rank.
An map generated at compile time where the key is the char of one of the alternatives and the value is the corresponding rank over all alternatives (by conflict will default to the first).
|
staticconstexprprivate |
Compile-time generated lookup table which contains the partial sum up to the position of each alternative.
An array which contains the prefix sum over all alternative_types::alphabet_size's.
|
staticconstexprprivate |
Compile-time generated lookup table which maps the rank to char.
A map generated at compile time where the key is the rank of the variant of all alternatives and the value is the corresponding char of that rank and alternative.