53template <
typename derived_type,
size_t size,
typename char_t =
char>
57 static_assert(
size != 0,
"alphabet size must be >= 1");
79 constexpr base() noexcept = default;
80 constexpr
base(
base const &) noexcept = default;
82 constexpr
base & operator=(
base const &) noexcept = default;
83 constexpr
base & operator=(
base &&) noexcept = default;
84 ~
base() noexcept = default;
107 return derived_type::rank_to_char[rank];
146 requires(!std::same_as<char_t, void>)
149 rank = derived_type::char_to_rank[
static_cast<index_t
>(c)];
150 return static_cast<derived_type &
>(*this);
170 assert(
static_cast<size_t>(c) <
static_cast<size_t>(
alphabet_size));
172 return static_cast<derived_type &
>(*this);
183 friend constexpr bool operator==(derived_type
const lhs, derived_type
const rhs)
185 return lhs.to_rank() == rhs.to_rank();
189 friend constexpr auto operator<=>(derived_type
const lhs, derived_type
const rhs)
191 return lhs.to_rank() <=> rhs.to_rank();
210 return a.assign_rank(r);
232 return a.assign_char(c);
239 derived_type::char_is_valid(c)
243 return derived_type::char_is_valid(c);
252 derived_type::char_is_valid(c)
256 return derived_type::char_is_valid(c);
285template <
typename derived_type,
typename char_t>
302 constexpr base() noexcept = default;
305 constexpr
base & operator=(
base const &) noexcept = default;
306 constexpr
base & operator=(
base &&) noexcept = default;
317 return derived_type::char_value;
329 requires(!std::same_as<char_t, void>)
331 return static_cast<derived_type &
>(*this);
345 friend constexpr bool operator==(derived_type
const, derived_type
const)
noexcept {
return true; }
348 friend constexpr bool operator<(derived_type
const, derived_type
const)
noexcept {
return false; }
351 friend constexpr bool operator>(derived_type
const, derived_type
const)
noexcept {
return false; }
354 friend constexpr bool operator<=(derived_type
const, derived_type
const)
noexcept {
return true; }
357 friend constexpr bool operator>=(derived_type
const, derived_type
const)
noexcept {
return true; }
395 derived_type::char_is_valid(c)
397 } && std::is_nothrow_default_constructible_v<derived_type>)
399 return derived_type::char_is_valid(c);
408 derived_type::char_is_valid(c)
410 } && !std::is_nothrow_default_constructible_v<derived_type>)
412 return derived_type::char_is_valid(c);
Core alphabet concept and free function/type trait wrappers.
friend constexpr bool operator<=(derived_type const, derived_type const) noexcept
Letters are always equal.
Definition: base.hpp:354
friend constexpr bool tag_invoke(custom::char_is_valid_for, char_type const c, derived_type) noexcept
tag_invoke() wrapper around member.
Definition: base.hpp:392
friend constexpr derived_type & tag_invoke(custom::assign_rank_to, rank_type const, derived_type &a) noexcept
tag_invoke() wrapper around member.
Definition: base.hpp:364
constexpr derived_type & assign_char(char_type const) noexcept
Assign from a character, implicitly converts invalid characters.
Definition: base.hpp:328
friend constexpr bool tag_invoke(custom::char_is_valid_for, char_type const c, std::type_identity< derived_type >) noexcept
tag_invoke() wrapper around member.
Definition: base.hpp:403
uint8_t rank_type
The type of the alphabet when represented as a number (e.g. via to_rank()).
Definition: base.hpp:295
friend constexpr derived_type & tag_invoke(custom::assign_char_to, char_type const c, derived_type &a) noexcept
tag_invoke() wrapper around member.
Definition: base.hpp:381
friend consteval auto tag_invoke(custom::size, std::type_identity< derived_type >) noexcept
tag_invoke() wrapper around member.
Definition: base.hpp:423
constexpr base() noexcept=default
Defaulted.
constexpr derived_type & assign_rank(rank_type const) noexcept
Assign from a numeric value.
Definition: base.hpp:335
friend constexpr bool operator>=(derived_type const, derived_type const) noexcept
Letters are always equal.
Definition: base.hpp:357
friend constexpr bool operator<(derived_type const, derived_type const) noexcept
One letter cannot be smaller than another.
Definition: base.hpp:348
friend constexpr auto tag_invoke(custom::to_char, derived_type const a) noexcept
tag_invoke() wrapper around member.
Definition: base.hpp:370
friend constexpr bool operator==(derived_type const, derived_type const) noexcept
Letters are always equal.
Definition: base.hpp:345
friend constexpr bool operator>(derived_type const, derived_type const) noexcept
One letter cannot be bigger than another.
Definition: base.hpp:351
friend constexpr rank_type tag_invoke(custom::to_rank, derived_type) noexcept
tag_invoke() wrapper around member.
Definition: base.hpp:361
friend consteval auto tag_invoke(custom::size, derived_type) noexcept
tag_invoke() wrapper around member.
Definition: base.hpp:416
constexpr rank_type to_rank() const noexcept
Return the letter's numeric value (rank in the alphabet).
Definition: base.hpp:321
A CRTP-base that makes defining a custom alphabet easier.
Definition: base.hpp:55
friend constexpr auto operator<=>(derived_type const lhs, derived_type const rhs)
Checks order of lhs and rhs.
Definition: base.hpp:189
friend constexpr bool operator==(derived_type const lhs, derived_type const rhs)
Checks whether the letters lhs and rhs are equal.
Definition: base.hpp:183
constexpr derived_type & assign_rank(rank_type const c) noexcept
Assign from a numeric value.
Definition: base.hpp:168
friend constexpr bool tag_invoke(custom::char_is_valid_for, char_type const c, derived_type) noexcept
tag_invoke() wrapper around member.
Definition: base.hpp:236
friend constexpr derived_type & tag_invoke(custom::assign_char_to, char_type const c, derived_type &a) noexcept
tag_invoke() wrapper around member.
Definition: base.hpp:225
friend consteval auto tag_invoke(custom::size, std::type_identity< derived_type >) noexcept
tag_invoke() wrapper around member.
Definition: base.hpp:267
friend constexpr auto tag_invoke(custom::to_rank, derived_type const a) noexcept
tag_invoke() wrapper around member.
Definition: base.hpp:200
static constexpr size_t alphabet_size
The size of the alphabet, i.e. the number of different values it can take.
Definition: base.hpp:177
constexpr char_type to_char() const noexcept
Return the letter as a character of char_type.
Definition: base.hpp:104
meta::detail::min_viable_uint_t< size - 1 > rank_type
The type of the alphabet when represented as a number (e.g. via to_rank()).
Definition: base.hpp:65
constexpr derived_type & assign_char(char_type const c) noexcept
Assign from a character, implicitly converts invalid characters.
Definition: base.hpp:145
constexpr base() noexcept=default
Defaulted.
friend constexpr auto tag_invoke(custom::to_char, derived_type const a) noexcept
tag_invoke() wrapper around member.
Definition: base.hpp:214
friend constexpr derived_type & tag_invoke(custom::assign_rank_to, rank_type const r, derived_type &a) noexcept
tag_invoke() wrapper around member.
Definition: base.hpp:203
friend constexpr bool tag_invoke(custom::char_is_valid_for, char_type const c, std::type_identity< derived_type >) noexcept
tag_invoke() wrapper around member.
Definition: base.hpp:247
friend consteval auto tag_invoke(custom::size, derived_type) noexcept
tag_invoke() wrapper around member.
Definition: base.hpp:260
constexpr rank_type to_rank() const noexcept
Return the letter's numeric value (rank in the alphabet).
Definition: base.hpp:124
constexpr auto size
A type trait that holds the size of a (semi-)alphabet.
Definition: concept.hpp:517
decltype(bio::alphabet::to_char(std::declval< alphabet_type const >())) char_t
The char_type of the alphabet; defined as the return type of bio::alphabet::to_char.
Definition: concept.hpp:212
Provides metaprogramming utilities for integer types.
The alphabet module's namespace.
Definition: aa10li.hpp:23
Customisation tag for bio::alphabet::assign_char_to.
Definition: tag.hpp:37
Customisation tag for bio::alphabet::assign_rank_to.#.
Definition: tag.hpp:29
Customisation tag for bio::alphabet::assign_char_to.
Definition: tag.hpp:41
CPO tag definition for bio::alphabet::size.
Definition: tag.hpp:45
Customisation tag for bio::alphabet::to_char.
Definition: tag.hpp:33
Customisation tag for bio::alphabet::to_rank.
Definition: tag.hpp:25