SeqAn3  3.0.0
The Modern C++ library for sequence analysis.
seqan3::Alphabet Interface Reference

The generic alphabet concept that covers most data types used in ranges. More...

#include <seqan3/alphabet/concept.hpp>

+ Inheritance diagram for seqan3::Alphabet:

Related Functions

(Note that these are not member functions.)

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

Detailed Description

The generic alphabet concept that covers most data types used in ranges.

This is the core alphabet concept that many other alphabet concepts refine.

For a detailed overview of how the different alphabet concepts are related, see Alphabet module.

Requirements

  1. t shall model seqan3::Semialphabet ("has all rank representation")
  2. seqan3::to_char needs to be defined for objects of type t

See the documentation pages for the respective requirements.

Related types

If a given type t models this concept, the following types typically do so, as well:

  • t &
  • t const
  • t const &

Writing your own alphabet

This is an example of a minimal custom alphabet that provides implementations for all necessary customisation points:

#include <cstddef> // for size_t
#include <seqan3/alphabet/concept.hpp> // for seqan3::Alphabet
namespace my_namespace
{
enum class my_alph
{
ZERO,
ONE,
TWO
};
constexpr size_t alphabet_size(my_alph const &) noexcept
{
return 3;
}
constexpr size_t to_rank(my_alph const a) noexcept
{
return static_cast<size_t>(a);
}
constexpr my_alph & assign_rank_to(size_t const r, my_alph & a) noexcept
{
switch (r)
{
case 0: a = my_alph::ZERO; return a;
case 1: a = my_alph::ONE; return a;
default: a = my_alph::TWO; return a;
}
}
constexpr char to_char(my_alph const a) noexcept
{
switch (a)
{
case my_alph::ZERO: return '0';
case my_alph::ONE: return '1';
default: return '2';
}
}
constexpr my_alph & assign_char_to(char const c, my_alph & a) noexcept
{
switch (c)
{
case '0': a = my_alph::ZERO; return a;
case '1': a = my_alph::ONE; return a;
default: a = my_alph::TWO; return a;
}
}
} // namespace my_namespace

This is an example of a custom alphabet that is not default-constructible and that has a non-default overload for seqan3::char_is_valid_for:

#include <cstddef> // for size_t
#include <seqan3/alphabet/concept.hpp> // for seqan3::Alphabet
#include <seqan3/std/type_traits> // for std::type_identity
namespace my_namespace
{
class my_alph
{
public:
bool b;
my_alph() = delete;
constexpr my_alph(my_alph const &) = default;
constexpr my_alph & operator=(my_alph const &) = default;
constexpr my_alph(bool _b) : b{_b} {}
constexpr friend bool operator==(my_alph lhs, my_alph rhs) { return lhs.b == rhs.b; }
constexpr friend bool operator!=(my_alph lhs, my_alph rhs) { return lhs.b != rhs.b; }
constexpr friend bool operator<=(my_alph lhs, my_alph rhs) { return lhs.b <= rhs.b; }
constexpr friend bool operator>=(my_alph lhs, my_alph rhs) { return lhs.b >= rhs.b; }
constexpr friend bool operator< (my_alph lhs, my_alph rhs) { return lhs.b < rhs.b; }
constexpr friend bool operator> (my_alph lhs, my_alph rhs) { return lhs.b > rhs.b; }
};
constexpr size_t alphabet_size(std::type_identity<my_alph> const &) noexcept
{
return 2;
}
constexpr bool to_rank(my_alph const a) noexcept
{
return a.b;
}
constexpr my_alph & assign_rank_to(bool const r, my_alph & a) noexcept
{
a.b = r;
return a;
}
constexpr char to_char(my_alph const a) noexcept
{
if (a.b)
return '1';
else
return '0';
}
constexpr my_alph & assign_char_to(char const c, my_alph & a) noexcept
{
switch (c)
{
case '0': case 'F': case 'f': a.b = 0; return a;
default: a.b = 1; return a;
}
}
constexpr bool char_is_valid_for(char const c, std::type_identity<my_alph> const &) noexcept
{
switch (c)
{
case '0': case 'F': case 'f': case '1': case 'T': case 't': return true;
default: return false;
}
}
} // namespace my_namespace
static_assert(seqan3::alphabet_size<my_namespace::my_alph> == 2);
static_assert(seqan3::char_is_valid_for<my_namespace::my_alph>('T'));
static_assert(!seqan3::char_is_valid_for<my_namespace::my_alph>('!'));

(Note that you should really make your alphabet types no-throw-default-constructible if you can!)


The documentation for this interface was generated from the following file: