SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
seqan3::alphabet_variant< alternative_types > Class Template Reference

A combined alphabet that can hold values of either of its alternatives.. More...

#include <seqan3/alphabet/composite/alphabet_variant.hpp>

+ Inheritance diagram for seqan3::alphabet_variant< alternative_types >:

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_variantoperator= (alphabet_variant const &) noexcept=default
 Defaulted.
 
constexpr alphabet_variantoperator= (alphabet_variant &&) noexcept=default
 Defaulted.
 
 ~alphabet_variant () noexcept=default
 Defaulted.
 
template<typename alternative_t >
requires (!std::same_as<alternative_t, alphabet_variant>) && (!detail::is_span<alternative_t>::value) && (!std::is_base_of_v<alphabet_variant, alternative_t>) && (!list_traits::contains< alphabet_variant, detail::transformation_trait_or_t<detail::recursive_required_types<alternative_t>, type_list<>>>) && (is_alternative<alternative_t>())
constexpr alphabet_variant (alternative_t const alternative) noexcept
 Construction via the value of an alternative.
 
template<typename indirect_alternative_t >
requires (!detail::is_span<indirect_alternative_t>::value) && (( detail::instantiate_if_v<detail::lazy<std::is_convertible, indirect_alternative_t, alternative_types>, detail::variant_general_guard<indirect_alternative_t, alternative_types...>> || ...))
constexpr alphabet_variant (indirect_alternative_t const rhs) noexcept
 Constructor for arguments implicitly convertible to an alternative.
 
template<typename indirect_alternative_t >
requires ( (!(detail::instantiate_if_v<detail::lazy<std::is_convertible, indirect_alternative_t, alternative_types>, detail::variant_general_guard<indirect_alternative_t, alternative_types...>> || ...)) && (detail::instantiate_if_v<detail::lazy<std::is_constructible, alternative_types, indirect_alternative_t>, detail::variant_general_guard<indirect_alternative_t, alternative_types...>> || ...))
constexpr alphabet_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...> && (weakly_assignable_from<alternative_types, indirect_alternative_t> || ...))
constexpr alphabet_variantoperator= (indirect_alternative_t const &rhs) noexcept
 Assignment for arguments assignable to an alternative.
 
Conversion (by index)
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).
 
Conversion (by type)
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).
 
- Public Member Functions inherited from seqan3::alphabet_base< alphabet_variant< alternative_types... >,(static_cast< size_t >(alphabet_size< alternative_types >)+...), char >
constexpr alphabet_base () noexcept=default
 Defaulted.
 
constexpr alphabet_base (alphabet_base const &) noexcept=default
 Defaulted.
 
constexpr alphabet_base (alphabet_base &&) noexcept=default
 Defaulted.
 
constexpr alphabet_baseoperator= (alphabet_base const &) noexcept=default
 Defaulted.
 
constexpr alphabet_baseoperator= (alphabet_base &&) noexcept=default
 Defaulted.
 
 ~alphabet_base () noexcept=default
 Defaulted.
 
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 alphabet_variant< alternative_types... > & assign_char (char_type const chr) noexcept
 Assign from a character, implicitly converts invalid characters.
 
constexpr alphabet_variant< alternative_types... > & assign_rank (rank_type const c) noexcept
 Assign from a numeric value.
 

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 is_alternative () noexcept
 Returns true if alternative_t is one of the given alternative types.
 

Private Types

using alternatives = seqan3::type_list< alternative_types... >
 A seqan3::type_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) -> seqan3::list_traits::at< index, alternatives >
 Implementation function for convert_to() and convert_unsafely_to().
 

Static Private Member Functions

static constexpr rank_type char_to_rank (char_type const chr)
 Compile-time generated lookup table which maps the char to rank.
 
template<size_t index, typename alternative_t >
requires (is_alternative<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.
 
template<typename alternative_t >
requires (is_alternative<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.
 
static constexpr char_type rank_to_char (rank_type const rank)
 Compile-time generated lookup table which maps the rank to char.
 

Private Attributes

friend base_t
 Befriend the base type.
 

Static Private Attributes

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.
 
static constexpr auto first_valid_char_table
 Compile-time generated lookup table which maps the char to the index of the first alphabet that fulfils char_is_valid_for.
 
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.
 
static constexpr std::array< char_type, alphabet_sizerank_to_char_table
 Compile-time generated lookup table which maps the rank to char.
 

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. alphabet_variant<seqan3::rna4, seqan3::gap> vs alphabet_variant<seqan3::dna4, seqan3::gap>. Only (in-)equality comparison is defined as reasoning about order of variants is inherently difficult.

template<typename alphabet_variant_t , typename indirect_alternative_type >
requires (!detail::is_span<alphabet_variant_t>::value) && (detail::variant_comparison_guard<alphabet_variant_t, indirect_alternative_type, false, alternative_types...>)
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 variant.
 
template<typename alphabet_variant_t , typename indirect_alternative_type >
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 variant.
 
template<typename alphabet_variant_t , typename indirect_alternative_type , typename = void>
requires (!detail::is_span<alphabet_variant_t>::value) && (detail::variant_comparison_guard<alphabet_variant_t, indirect_alternative_type, true, alternative_types...>)
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 variant.
 
template<typename alphabet_variant_t , typename indirect_alternative_type , typename = void>
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 variant.
 
Comparison operators

Additional Inherited Members

- Static Public Attributes inherited from seqan3::alphabet_base< alphabet_variant< alternative_types... >,(static_cast< size_t >(alphabet_size< alternative_types >)+...), char >
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.
 
- Protected Types inherited from seqan3::alphabet_base< alphabet_variant< alternative_types... >,(static_cast< size_t >(alphabet_size< alternative_types >)+...), char >
using char_type = std::conditional_t< std::same_as< 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()).
 

Detailed Description

template<typename... alternative_types>
requires (detail::writable_constexpr_alphabet<alternative_types> && ...) && (std::regular<alternative_types> && ...) && (sizeof...(alternative_types) >= 2)
class seqan3::alphabet_variant< alternative_types >

A combined alphabet that can hold values of either of its alternatives.

.

Template Parameters
...alternative_typesTypes 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:

  • combines multiple different alphabets in an "either-or"-fashion;
  • is itself a seqan3::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

// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
int main()
{
using namespace seqan3::literals;
seqan3::alphabet_variant<seqan3::dna5, seqan3::gap> letter{}; // implicitly 'A'_dna5
seqan3::alphabet_variant<seqan3::dna5, seqan3::gap> letter2{'C'_dna5}; // constructed from alternative (== 'C'_dna5)
'U'_rna5}; // constructed from type that alternative is constructible from (== 'T'_dna5)
letter2.assign_char('T'); // == 'T'_dna5
letter2.assign_char('-'); // == gap{}
letter2.assign_char('K'); // unknown characters map to the default/unknown
// character of the first alternative type (== 'N'_dna5)
letter2 = seqan3::gap{}; // assigned from alternative (== gap{})
letter2 = 'U'_rna5; // assigned from type that alternative is assignable from (== 'T'_dna5)
seqan3::dna5 letter4 = letter2.convert_to<seqan3::dna5>();
}
Meta-header for the Alphabet / Nucleotide submodule .
Provides seqan3::alphabet_variant.
constexpr derived_type & assign_char(char_type const chr) noexcept
Assign from a character, implicitly converts invalid characters.
Definition alphabet_base.hpp:160
A combined alphabet that can hold values of either of its alternatives..
Definition alphabet_variant.hpp:129
The five letter DNA alphabet of A,C,G,T and the unknown character N.
Definition dna5.hpp:48
The alphabet of a gap character '-'.
Definition gap.hpp:36
Provides seqan3::gap.
The SeqAn namespace for literals.

The char representation of an alphabet_variant

Part 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, representingN`_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 anA`_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.

// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
int main()
{
using namespace seqan3::literals;
var.assign_char('A'); // will be in the "dna4-state"
var = 'A'_dna5; // will be in the "dna5-state"
}

This entity is stable. Since version 3.1.

Member Typedef Documentation

◆ seqan3_recursive_required_types

template<typename... alternative_types>
using seqan3::alphabet_variant< alternative_types >::seqan3_recursive_required_types = list_traits::concat< seqan3_required_types, detail::transformation_trait_or_t<detail::recursive_required_types<alternative_types>, type_list<> >...>
private

Expose the recursive alternative types to concept checks in metaprogramming.

This entity is not part of the SeqAn API. Do not rely on it in your applications.

◆ seqan3_required_types

template<typename... alternative_types>
using seqan3::alphabet_variant< alternative_types >::seqan3_required_types = type_list<alternative_types...>
private

Expose the alternative types to concept checks in metaprogramming.

This entity is not part of the SeqAn API. Do not rely on it in your applications.

Constructor & Destructor Documentation

◆ alphabet_variant() [1/3]

template<typename... alternative_types>
template<typename alternative_t >
requires (!std::same_as<alternative_t, alphabet_variant>) && (!detail::is_span<alternative_t>::value) && (!std::is_base_of_v<alphabet_variant, alternative_t>) && (!list_traits::contains< alphabet_variant, detail::transformation_trait_or_t<detail::recursive_required_types<alternative_t>, type_list<>>>) && (is_alternative<alternative_t>())
constexpr seqan3::alphabet_variant< alternative_types >::alphabet_variant ( alternative_t const  alternative)
inlineconstexprnoexcept

Construction via the value of an alternative.

Template Parameters
alternative_tOne of the alternative types.
Parameters
alternativeThe value of a alternative that should be assigned.
// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
int main()
{
using namespace seqan3::literals;
}

This entity is stable. Since version 3.1.

◆ alphabet_variant() [2/3]

template<typename... alternative_types>
template<typename indirect_alternative_t >
requires (!detail::is_span<indirect_alternative_t>::value) && (( detail::instantiate_if_v<detail::lazy<std::is_convertible, indirect_alternative_t, alternative_types>, detail::variant_general_guard<indirect_alternative_t, alternative_types...>> || ...))
constexpr seqan3::alphabet_variant< alternative_types >::alphabet_variant ( indirect_alternative_t const  rhs)
inlineconstexprnoexcept

Constructor for arguments implicitly convertible to an alternative.

Template Parameters
indirect_alternative_tA type that is implicitly convertible to an alternative type.
Parameters
rhsThe value that should be assigned.

This constructor is preferred over the explicit version.

Example

// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
int main()
{
using namespace seqan3::literals;
}
  • seqan3::dna4 and seqan3::rna4 are implicitly convertible to each other so the variant accepts either.
  • Construction via {} considers implicit and explicit conversions.
  • Construction via = considers only implicit conversions (but that is sufficient here).

This entity is experimental and subject to change in the future. Experimental since version 3.1.

◆ alphabet_variant() [3/3]

template<typename... alternative_types>
template<typename indirect_alternative_t >
requires ( (!(detail::instantiate_if_v<detail::lazy<std::is_convertible, indirect_alternative_t, alternative_types>, detail::variant_general_guard<indirect_alternative_t, alternative_types...>> || ...)) && (detail::instantiate_if_v<detail::lazy<std::is_constructible, alternative_types, indirect_alternative_t>, detail::variant_general_guard<indirect_alternative_t, alternative_types...>> || ...))
constexpr seqan3::alphabet_variant< alternative_types >::alphabet_variant ( indirect_alternative_t const  rhs)
inlineexplicitconstexprnoexcept

Constructor for arguments explicitly (but not implicitly) convertible to an alternative.

Template Parameters
indirect_alternative_tA type that is explicitly (but not implicitly) convertible to an alternative type.
Parameters
rhsThe value that should be assigned.

Example

// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
int main()
{
using namespace seqan3::literals;
// possible:
// not possible:
// seqan3::alphabet_variant<seqan3::dna4, seqan3::gap> letter2 = 'C'_dna5;
}
  • seqan3::dna4 and seqan3::dna5 are not implicitly convertible to each other, only explicitly.
  • Construction via {} considers implicit and explicit conversions so this works.
  • Construction via = considers only implicit conversions so it does not work.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

Member Function Documentation

◆ char_is_valid()

template<typename... alternative_types>
static constexpr bool seqan3::alphabet_variant< alternative_types >::char_is_valid ( char_type const  chr)
inlinestaticconstexprnoexcept

Validate whether a character is valid in the combined alphabet.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

◆ char_to_rank()

template<typename... alternative_types>
static constexpr rank_type seqan3::alphabet_variant< alternative_types >::char_to_rank ( char_type const  chr)
inlinestaticconstexprprivate

Compile-time generated lookup table which maps the char to rank.

A 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).

◆ convert_impl()

template<typename... alternative_types>
template<size_t index, bool throws>
constexpr auto seqan3::alphabet_variant< alternative_types >::convert_impl ( ) const -> seqan3::list_traits::at<index, alternatives>
inlineconstexprprivatenoexcept

Implementation function for convert_to() and convert_unsafely_to().

Template Parameters
indexIndex of the alternative to convert to.
throwsWhether to perform checks (and throw) or not.

◆ convert_to() [1/2]

template<typename... alternative_types>
template<size_t index>
constexpr auto seqan3::alphabet_variant< alternative_types >::convert_to ( ) const
inlineconstexpr

Convert to the specified alphabet (throws if holds_alternative() would be false).

Template Parameters
indexIndex of the alternative to check for.
Exceptions
std::bad_variant_accessIf the variant_alphabet currently holds the value of a different alternative.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

◆ convert_to() [2/2]

template<typename... alternative_types>
template<typename alternative_t >
requires (is_alternative<alternative_t>())
constexpr alternative_t seqan3::alphabet_variant< alternative_types >::convert_to ( ) const
inlineconstexpr

Convert to the specified alphabet (throws if holds_alternative() would be false).

Template Parameters
alternative_tThe type of the alternative that you wish to check for.
Exceptions
std::bad_variant_accessIf the variant_alphabet currently holds the value of a different alternative.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

◆ convert_unsafely_to() [1/2]

template<typename... alternative_types>
template<size_t index>
constexpr auto seqan3::alphabet_variant< alternative_types >::convert_unsafely_to ( ) const
inlineconstexprnoexcept

Convert to the specified alphabet (undefined behaviour if holds_alternative() would be false).

Template Parameters
indexIndex of the alternative to check for.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

◆ convert_unsafely_to() [2/2]

template<typename... alternative_types>
template<typename alternative_t >
requires (is_alternative<alternative_t>())
constexpr alternative_t seqan3::alphabet_variant< alternative_types >::convert_unsafely_to ( ) const
inlineconstexprnoexcept

Convert to the specified alphabet (undefined behaviour if holds_alternative() would be false).

Template Parameters
alternative_tThe type of the alternative that you wish to check for.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

◆ holds_alternative() [1/2]

template<typename... alternative_types>
template<size_t index>
constexpr bool seqan3::alphabet_variant< alternative_types >::holds_alternative ( ) const
inlineconstexprnoexcept

Whether the variant alphabet currently holds a value of the given alternative.

Template Parameters
indexIndex of the alternative to check for.
See also
std::variant::holds_alternative

This entity is experimental and subject to change in the future. Experimental since version 3.1.

◆ holds_alternative() [2/2]

template<typename... alternative_types>
template<typename alternative_t >
requires (is_alternative<alternative_t>())
constexpr bool seqan3::alphabet_variant< alternative_types >::holds_alternative ( ) const
inlineconstexprnoexcept

Whether the variant alphabet currently holds a value of the given alternative.

Template Parameters
alternative_tThe type of the alternative that you wish to check for.

This entity is stable. Since version 3.1.

◆ is_alternative()

template<typename... alternative_types>
template<typename alternative_t >
static constexpr bool seqan3::alphabet_variant< alternative_types >::is_alternative ( )
inlinestaticconstexprnoexcept

Returns true if alternative_t is one of the given alternative types.

Template Parameters
alternative_tThe type to check.
// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <gtest/gtest.h>
int main()
{
static_assert(variant_t::is_alternative<seqan3::dna5>(), "dna5 is an alternative of variant_t");
static_assert(!variant_t::is_alternative<seqan3::dna4>(), "dna4 is not an alternative of variant_t");
static_assert(variant_t::is_alternative<seqan3::gap>(), "gap is an alternative of variant_t");
}

This entity is stable. Since version 3.1.

◆ operator=()

template<typename... alternative_types>
template<typename indirect_alternative_t >
requires (detail::variant_general_guard<indirect_alternative_t, alternative_types...> && (weakly_assignable_from<alternative_types, indirect_alternative_t> || ...))
constexpr alphabet_variant & seqan3::alphabet_variant< alternative_types >::operator= ( indirect_alternative_t const &  rhs)
inlineconstexprnoexcept

Assignment for arguments assignable to an alternative.

Template Parameters
indirect_alternative_tA type that one of the alternatives is assignable from.
Parameters
rhsThe value of an alternative.

Most assignments happen through implicit conversion and the default assignment operator. This assignment operator is for the rest.

This entity is experimental and subject to change in the future. Experimental since version 3.1.

◆ rank_by_index_()

template<typename... alternative_types>
template<size_t index, typename alternative_t >
requires (is_alternative<alternative_t>())
static constexpr rank_type seqan3::alphabet_variant< alternative_types >::rank_by_index_ ( alternative_t const &  alternative)
inlinestaticconstexprprivatenoexcept

Converts an object of one of the given alternatives into the internal representation.

Template Parameters
indexThe position of alternative_t in the template pack alternative_types.
alternative_tOne of the alternative types.
Parameters
alternativeThe value of a alternative.

◆ rank_by_type_()

template<typename... alternative_types>
template<typename alternative_t >
requires (is_alternative<alternative_t>())
static constexpr rank_type seqan3::alphabet_variant< alternative_types >::rank_by_type_ ( alternative_t const &  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.

Template Parameters
alternative_tOne of the alternative types.
Parameters
alternativeThe value of a alternative.

◆ rank_to_char()

template<typename... alternative_types>
static constexpr char_type seqan3::alphabet_variant< alternative_types >::rank_to_char ( rank_type const  rank)
inlinestaticconstexprprivate

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.

Friends And Related Symbol Documentation

◆ operator!= [1/2]

template<typename... alternative_types>
template<typename alphabet_variant_t , typename indirect_alternative_type >
constexpr auto operator!= ( alphabet_variant_t const  lhs,
indirect_alternative_type const  rhs 
) -> std::enable_if_t< detail::variant_comparison_guard<alphabet_variant_t, indirect_alternative_type, false, alternative_types...>, bool>
friend

(In-)Equality comparison against types comparable with alternatives but not convertible to the variant.

Template Parameters
alphabet_variant_tThe type of the variant; given as template parameter to prevent conversion.
indirect_alternative_typeMust be comparable with an alternative's type.
Parameters
lhsLeft-hand-side of comparison.
rhsRight-hand-side of comparison.
Returns
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.

This entity is stable. Since version 3.1.

◆ operator!= [2/2]

template<typename... alternative_types>
template<typename alphabet_variant_t , typename indirect_alternative_type , typename = void>
constexpr auto operator!= ( indirect_alternative_type const  lhs,
alphabet_variant_t const  rhs 
) -> std::enable_if_t< detail::variant_comparison_guard<alphabet_variant_t, indirect_alternative_type, true, alternative_types...>, bool>
friend

(In-)Equality comparison against types comparable with alternatives but not convertible to the variant.

Template Parameters
alphabet_variant_tThe type of the variant; given as template parameter to prevent conversion.
indirect_alternative_typeMust be comparable with an alternative's type.
Parameters
lhsLeft-hand-side of comparison.
rhsRight-hand-side of comparison.
Returns
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.

This entity is stable. Since version 3.1.

◆ operator== [1/2]

template<typename... alternative_types>
template<typename alphabet_variant_t , typename indirect_alternative_type >
requires (!detail::is_span<alphabet_variant_t>::value) && (detail::variant_comparison_guard<alphabet_variant_t, indirect_alternative_type, false, alternative_types...>)
constexpr bool operator== ( alphabet_variant_t const  lhs,
indirect_alternative_type const  rhs 
)
friend

(In-)Equality comparison against types comparable with alternatives but not convertible to the variant.

Template Parameters
alphabet_variant_tThe type of the variant; given as template parameter to prevent conversion.
indirect_alternative_typeMust be comparable with an alternative's type.
Parameters
lhsLeft-hand-side of comparison.
rhsRight-hand-side of comparison.
Returns
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.

This entity is stable. Since version 3.1.

◆ operator== [2/2]

template<typename... alternative_types>
template<typename alphabet_variant_t , typename indirect_alternative_type , typename = void>
requires (!detail::is_span<alphabet_variant_t>::value) && (detail::variant_comparison_guard<alphabet_variant_t, indirect_alternative_type, true, alternative_types...>)
constexpr bool operator== ( indirect_alternative_type const  lhs,
alphabet_variant_t const  rhs 
)
friend

(In-)Equality comparison against types comparable with alternatives but not convertible to the variant.

Template Parameters
alphabet_variant_tThe type of the variant; given as template parameter to prevent conversion.
indirect_alternative_typeMust be comparable with an alternative's type.
Parameters
lhsLeft-hand-side of comparison.
rhsRight-hand-side of comparison.
Returns
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.

This entity is stable. Since version 3.1.

Member Data Documentation

◆ char_to_rank_table

template<typename... alternative_types>
constexpr std::array<rank_type, detail::size_in_values_v<char_type> > seqan3::alphabet_variant< alternative_types >::char_to_rank_table
staticconstexprprivate
Initial value:
{
[]() constexpr {
constexpr size_t alternative_size = sizeof...(alternative_types);
constexpr size_t table_size = detail::size_in_values_v<char_type>;
for (size_t i = 0u; i < table_size; ++i)
{
char_type chr = static_cast<char_type>(i);
char_to_rank[i] = first_valid_char_table[i] < alternative_size ? ranks[first_valid_char_table[i]] : 0;
}
return char_to_rank;
}()
}
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 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
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
constexpr auto assign_char_to
Assign a character to an alphabet object.
Definition alphabet/concept.hpp:521

Compile-time generated lookup table which maps the char to rank.

A 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).

◆ first_valid_char_table

template<typename... alternative_types>
constexpr auto seqan3::alphabet_variant< alternative_types >::first_valid_char_table
staticconstexprprivate
Initial value:
{
[]() constexpr {
constexpr size_t alternative_size = sizeof...(alternative_types);
constexpr size_t table_size = detail::size_in_values_v<char_type>;
using first_alphabet_t = detail::min_viable_uint_t<alternative_size>;
for (size_t i = 0u; i < table_size; ++i)
{
char_type chr = static_cast<char_type>(i);
std::array<bool, alternative_size> valid_chars{char_is_valid_for<alternative_types>(chr)...};
auto found_it = std::find(valid_chars.begin(), valid_chars.end(), true);
lookup_table[i] = found_it - valid_chars.begin();
}
return lookup_table;
}()
}
T find(T... args)

Compile-time generated lookup table which maps the char to the index of the first alphabet that fulfils char_is_valid_for.

◆ partial_sum_sizes

template<typename... alternative_types>
constexpr std::array<rank_type, sizeof...(alternative_types) + 1> seqan3::alphabet_variant< alternative_types >::partial_sum_sizes
staticconstexprprivate
Initial value:
{
[]() constexpr {
constexpr size_t N = sizeof...(alternative_types) + 1;
std::array<rank_type, N> partial_sum{0, seqan3::alphabet_size<alternative_types>...};
for (size_t i = 1u; i < N; ++i)
partial_sum[i] += partial_sum[i - 1];
return partial_sum;
}()
}

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.

◆ rank_to_char_table

template<typename... alternative_types>
constexpr std::array<char_type, alphabet_size> seqan3::alphabet_variant< alternative_types >::rank_to_char_table
staticconstexprprivate
Initial value:
{
[]() constexpr {
auto assign_value_to_char = [](auto alternative, auto & value_to_char, auto & value) constexpr
{
using alternative_t = std::decay_t<decltype(alternative)>;
for (size_t i = 0u; i < seqan3::alphabet_size<alternative_t>; ++i, ++value)
value_to_char[value] = seqan3::to_char(seqan3::assign_rank_to(i, alternative));
};
size_t value{};
((assign_value_to_char(alternative_types{}, value_to_char, value)), ...);
return value_to_char;
}()
}
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

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.


The documentation for this class was generated from the following file:
Hide me