BioC++ core-0.7.0
The Modern C++ libraries for Bioinformatics.
 
Loading...
Searching...
No Matches
Tag

Provides tagging utilities (often used in tag-dispatching). More...

+ Collaboration diagram for Tag:

Classes

struct  bio::meta::priority_tag< I >
 A tag that allows controlled overload resolution via implicit base conversion rules. More...
 
struct  bio::meta::priority_tag< 0 >
 Recursion anchor for bio::meta::priority_tag. More...
 
struct  bio::meta::vtag_t< vs >
 The type of bio::meta::vtag. [Declaration]. More...
 
struct  bio::meta::vtag_t< v >
 The type of bio::meta::vtag. [Specialisation for 1 argument]. More...
 
struct  bio::meta::vtag_t< vs... >
 The type of bio::meta::vtag. [Specialisation for 2 or more arguments]. More...
 
struct  bio::meta::vtag_t<>
 The type of bio::meta::vtag. [Specialisation for 0 arguments.]. More...
 

Functions

template<detail::literal_buffer_string str>
consteval auto bio::meta::literals::operator""_vtag () noexcept
 String literal operator for creating vtags.
 

Variables

template<typename type , typename... more_types>
constinit type_list< type, more_types... > bio::meta::ttag {}
 A type-tag template.
 
template<auto... vs>
constexpr vtag_t< vs... > bio::meta::vtag {}
 A value-tag template.
 

Detailed Description

Provides tagging utilities (often used in tag-dispatching).

Function Documentation

◆ operator""_vtag()

template<detail::literal_buffer_string str>
consteval auto bio::meta::literals::operator""_vtag ( )
noexcept

String literal operator for creating vtags.

Integer literal operator for creating vtags.

Template Parameters
strA buffer for the literal.

Creates bio::meta::vtag from a string literal.

The returned tag will be of type bio::meta::vtag_t<bio::ranges::small_string<str.size()>{str}>.

Example

The tags allow compile-time comparisons of the the string-literals:

void foo(auto tag)
{
using namespace bio::meta::literals;
// selection of path AT COMPILE TIME:
if constexpr (tag == "onething"_vtag)
{
// something
}
else
{
// something else
}
}
void bar()
{
using namespace bio::meta::literals;
foo("onething"_vtag); // triggers first path
foo("other"_vtag); // triggers second path
}
An inline namespace for meta literals. It exists to safely allow using namespace.

The allows very self-descriptive dispatching.

Template Parameters
chrsThe literal buffer.

Creates bio::meta::vtag from a numeric literal.

The returned tag will be of type bio::meta::vtag<int64_t{NUMBER}>, where NUMBER is the integer you passed.

Example

Reduces the verbosity of tag-dispatching:

void dispatchee2(bio::meta::vtag_t<int64_t{1}>) { /* do one thing */ }
void dispatchee2(bio::meta::vtag_t<int64_t{2}>) { /* do another thing */ }
void dispatcher2()
{
using namespace bio::meta::literals;
dispatchee2(1_vtag); // calls first overload
dispatchee2(2_vtag); // calls second overload
}
The type of bio::meta::vtag. [Declaration].
Definition: vtag.hpp:63

Negative literals are supported:

using namespace bio::meta::literals;
static_assert(1_vtag == bio::meta::vtag<1>);
static_assert(-1_vtag == bio::meta::vtag<-1>);
constexpr vtag_t< vs... > vtag
A value-tag template.
Definition: vtag.hpp:216

Variable Documentation

◆ ttag

template<typename type , typename... more_types>
constinit type_list<type, more_types...> bio::meta::ttag {}
inline

A type-tag template.

Template Parameters
typeThe first type to store.
more_typesMore types to store (optional).
See also
bio::meta::type_list

Using this template, you can easily turn a type into a compile-time constant (value).

Example

void bax(bio::meta::type_list<int>) { /* do one thing */ }
void bax(bio::meta::type_list<float>) { /* do another thing */ }
void bat()
{
bax(bio::meta::ttag<int>); // calls first overload
bax(bio::meta::ttag<float>); // calls second overload
/* the same as calling */
bax(bio::meta::type_list<int>{}); // calls first overload
bax(bio::meta::type_list<float>{}); // calls second overload
}
Type that contains multiple types.
Definition: type_list.hpp:30

◆ vtag

template<auto... vs>
constexpr vtag_t<vs...> bio::meta::vtag {}
inlineconstexpr

A value-tag template.

Template Parameters
vsThe values to store in the tag.

Using this template, you can easily turn a value, e.g. a literal value, into a compile-time constant with a unique type.

Example

Dispatching between two overloads:

void dispatchee(bio::meta::vtag_t<1>) { /* do one thing */ }
void dispatchee(bio::meta::vtag_t<2>) { /* do another thing */ }
void dispatcher()
{
dispatchee(bio::meta::vtag<1>); // calls first overload
dispatchee(bio::meta::vtag<2>); // calls second overload
}