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 |
Construction via the value of a type that an alternative type is constructible from. More... | |
template<typename indirect_alternative_t > | |
constexpr alphabet_variant & | operator= (indirect_alternative_t const &rhs) noexcept |
Assignment via a value that one of the alternative types is assignable from. 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 requires holds_alternative< alternative_t >() |
Whether the variant alphabet currently holds a value of the given alternative. More... | |
template<typename alternative_t > | |
constexpr alternative_t | convert_to () const requires holds_alternative< alternative_t >() |
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 requires holds_alternative< alternative_t >() |
Convert to the specified alphabet (undefined behaviour if is_alternative() would be false). More... | |
Comparison operators (against alternatives) | |
Defines comparison against alternatives, e.g. ‘alphabet_variant<dna5, gap>{gap{}} == 'C’_dna5`. Only (in-)equality comparison is explicitly defined, because it would be difficult to argue about e.g. ‘alphabet_variant<dna5, gap>{gap{}} < 'C’_dna5`. | |
template<typename alternative_t > | |
constexpr bool | operator== (alternative_t const rhs) const noexcept requires holds_alternative< alternative_t >() |
template<typename alternative_t > | |
constexpr bool | operator!= (alternative_t const rhs) const noexcept requires holds_alternative< alternative_t >() |
Comparison operators (against indirect alternatives) | |
Defines comparison against types that are comparable with alternatives, e.g. ‘alphabet_variant<dna5, gap>{'C’_dna5} == 'C'_rna5`. Only (in-)equality comparison is explicitly defined, because it would be difficult to argue about e.g. ‘alphabet_variant<dna5, gap>{gap{}} < 'C’_rna5`. | |
template<typename indirect_alternative_type > | |
constexpr bool | operator== (indirect_alternative_type const rhs) const noexcept |
template<typename indirect_alternative_type > | |
constexpr bool | operator!= (indirect_alternative_type const rhs) const noexcept |
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 | |
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 detail::min_viable_uint_t< size > constexpr | alphabet_size |
The size of the alphabet, i.e. the number of different values it can take. | |
Protected Types | |
Member types | |
using | char_type = std::conditional_t< std::Same< char, void >, char, char > |
The char representation; conditional needed to make semi alphabet definitions legal. | |
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()). | |
Related Functions | |
(Note that these are not member functions.) | |
Comparison operators | |
Free function (in-)equality comparison operators that forward to member operators (for types != self). | |
template<typename lhs_t , typename ... alternative_types> | |
constexpr bool | operator== (lhs_t const lhs, alphabet_variant< alternative_types... > const rhs) noexcept |
template<typename lhs_t , typename ... alternative_types> | |
constexpr bool | operator!= (lhs_t const lhs, alphabet_variant< alternative_types... > const rhs) noexcept |
Requirements for std::StrictTotallyOrdered | |
You can expect these functions on all types that implement std::StrictTotallyOrdered. | |
bool | operator< (type const &lhs, type const &rhs) |
Less-than, greater-than and -or-equal comparisons. More... | |
bool | operator<= (type const &lhs, type const &rhs) |
Less-than, greater-than and -or-equal comparisons. More... | |
bool | operator> (type const &lhs, type const &rhs) |
Less-than, greater-than and -or-equal comparisons. More... | |
bool | operator>= (type const &lhs, type const &rhs) |
Less-than, greater-than and -or-equal comparisons. More... | |
Requirements for std::EqualityComparable | |
You can expect these functions on all types that implement std::Equality_comparable. | |
bool | operator== (type const &lhs, type const &rhs) |
(In-)Equality comparison. More... | |
bool | operator!= (type const &lhs, type const &rhs) |
(In-)Equality comparison. More... | |
Requirements for std::Swappable | |
You can expect these functions on all types that implement std::Swappable. | |
void | swap (t &lhs, t &rhs) |
Swaps the contents of two objects. 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::WritableAlphabet, must not be references and must be unique; all required functions for seqan3::WritableAlphabet need to be callable in a constexpr -context. |
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.
|
inlinenoexcept |
Construction via the value of an alternative.
alternative_t | One of the alternative types. |
alternative | The value of a alternative that should be assigned. |
|
inlinenoexcept |
Construction via the value of a type that an alternative type is constructible from.
indirect_alternative_t | A type that one of the alternative types is constructible from. |
rhs | The value that should be assigned. |
|
inlinenoexceptinherited |
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.
|
inlinenoexceptinherited |
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.
|
inline |
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. |
|
inline |
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. |
|
inlinenoexcept |
Convert to the specified alphabet (undefined behaviour if is_alternative() would be false).
index | Index of the alternative to check for. |
|
inlinenoexcept |
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. |
|
inlinestaticnoexcept |
Returns true if alternative_t is one of the given alternative types.
alternative_t | The type to check. |
|
inlinenoexcept |
Whether the variant alphabet currently holds a value of the given alternative.
index | Index of the alternative to check for. |
|
inlinenoexcept |
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. |
|
inlinenoexcept |
Assignment via a value that one of the alternative types is assignable from.
indirect_alternative_t | A type that one of the alternatives is assignable from. |
rhs | The value of an alternative. |
|
inlinenoexceptinherited |
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.
|
inlinenoexceptinherited |
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.