|
|
constexpr | variant () noexcept=default |
| Defaulted.
|
|
constexpr | variant (variant const &) noexcept=default |
| Defaulted.
|
|
constexpr | variant (variant &&) noexcept=default |
| Defaulted.
|
|
constexpr variant & | operator= (variant const &) noexcept=default |
| Defaulted.
|
|
constexpr variant & | operator= (variant &&) noexcept=default |
| Defaulted.
|
|
| ~variant () noexcept=default |
| Defaulted.
|
|
template<typename alternative_t >
requires (is_alternative<alternative_t>()) |
constexpr | variant (alternative_t const alternative) noexcept |
| Construction via the value of an alternative.
|
|
template<typename indirect_alternative_t >
requires (detail::variant_general_guard<indirect_alternative_t, alternative_types...> && (std::is_convertible_v<indirect_alternative_t, alternative_types> || ...)) |
constexpr | variant (indirect_alternative_t const rhs) noexcept |
| Constructor for arguments implicitly convertible to an alternative.
|
|
template<typename indirect_alternative_t >
requires (detail::variant_general_guard<indirect_alternative_t, alternative_types...> && !(std::is_convertible_v<indirect_alternative_t, alternative_types> || ...) && (std::is_constructible_v<alternative_types, indirect_alternative_t> || ...)) |
constexpr | variant (indirect_alternative_t const rhs) noexcept |
| Constructor for arguments explicitly (but not implicitly) convertible to an alternative.
|
|
template<typename indirect_alternative_t >
requires (detail::variant_general_guard<indirect_alternative_t, alternative_types...> && (meta::weakly_assignable_from<alternative_types, indirect_alternative_t> || ...)) |
constexpr variant & | operator= (indirect_alternative_t const &rhs) noexcept |
| Assignment for arguments assignable to an alternative.
|
|
|
template<size_t index> |
constexpr bool | holds_alternative () const noexcept |
| Whether the variant alphabet currently holds a value of the given alternative.
|
|
template<size_t index> |
constexpr auto | convert_to () const |
| Convert to the specified alphabet (throws if holds_alternative() would be false).
|
|
template<size_t index> |
constexpr auto | convert_unsafely_to () const noexcept |
| Convert to the specified alphabet (undefined behaviour if holds_alternative() would be false).
|
|
|
template<typename alternative_t >
requires (is_alternative<alternative_t>()) |
constexpr bool | holds_alternative () const noexcept |
| Whether the variant alphabet currently holds a value of the given alternative.
|
|
template<typename alternative_t >
requires (is_alternative<alternative_t>()) |
constexpr alternative_t | convert_to () const |
| Convert to the specified alphabet (throws if holds_alternative() would be false).
|
|
template<typename alternative_t >
requires (is_alternative<alternative_t>()) |
constexpr alternative_t | convert_unsafely_to () const noexcept |
| Convert to the specified alphabet (undefined behaviour if holds_alternative() would be false).
|
|
|
constexpr char_type | to_char () const noexcept |
| Return the letter as a character of char_type.
|
|
constexpr rank_type | to_rank () const noexcept |
| Return the letter's numeric value (rank in the alphabet).
|
|
|
constexpr variant< alternative_types... > & | assign_char (char_type const c) noexcept |
| Assign from a character, implicitly converts invalid characters.
|
|
constexpr variant< alternative_types... > & | assign_rank (rank_type const c) noexcept |
| Assign from a numeric value.
|
|
template<typename... alternative_types>
requires ((detail::writable_constexpr_alphabet<alternative_types> && ...) && (std::regular<alternative_types> && ...) && (sizeof...(alternative_types) >= 2))
class bio::alphabet::variant< alternative_types >
A combined alphabet that can hold values of either of its alternatives.
.
- Template Parameters
-
The 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 bio::alphabet::alphabet.
Short description:
- combines multiple different alphabets in an "either-or"-fashion;
- is itself a bio::alphabet::alphabet;
- its alphabet size is the sum of the individual sizes;
- default initialises to the the first alternative's default (no empty state like std::variant);
- constructible, assignable and (in-)equality-comparable with each alternative type and also all types that these are constructible/assignable/equality-comparable with;
- only convertible to its alternatives through the member function convert_to() (which can throw!)
Example
int main()
{
letter2.assign_char('-');
letter2.assign_char('K');
letter2 = 'U'_rna5;
}
Meta-header for the nucleotide submodule; includes all headers from alphabet/nucleotide/.
constexpr derived_type & assign_char(char_type const c) noexcept
Assign from a character, implicitly converts invalid characters.
Definition: base.hpp:145
The five letter DNA alphabet of A,C,G,T and the unknown character N..
Definition: dna5.hpp:50
The alphabet of a gap character '-'.
Definition: gap.hpp:38
A combined alphabet that can hold values of either of its alternatives..
Definition: variant.hpp:104
Provides bio::alphabet::gap.
An inline namespace for alphabet literals. It exists to safely allow using namespace.
Definition: aa10li.hpp:183
Provides bio::alphabet::variant.
The char
representation of an variant
Part of the bio::alphabet::alphabet concept requires that the variant provides a char representation in addition to the rank representation. For an object of bio::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 bio::alphabet::dna15 resolves to an object of rank 8 with char representation 'N' while assigning '!' to bio::alphabet::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. ‘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. ‘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.
int main()
{
var = 'A'_dna5;
}