template <typename... T>
muu::type_list struct

A 'tag' type for encoding/parameterizing lists of types (without the instantiation heft of std::tuple).

Template parameters
T The list of types represented by the list.

This type is not simply std::tuple without the container functionality! The underlying template machinery is highly optimized to reduce instantiation burden for even very massive type lists.

Public types

template <typename... U>
using append = muu::type_list<T..., U...>
Creates a new type list by appending types to this one.
using first = /* ... */
The first type in the list.
using flatten = /* ... */
A flattened version of the list with any nested type_lists recursively hoisted up into itself.
template <typename... U>
using prepend = muu::type_list<U..., T...>
Creates a new type list by prepending types to this one.
template <typename U>
using remove = /* ... */
A version of the list with all ocurrences of the named type removed.
template <size_t Index>
using select = /* ... */
Selects a single type from the list.
template <size_t Start, size_t Length = (length - Start)>
using slice = /* ... */
Selects a slice of types from the list.
using type = first
Alias for first when length == 1.

Public static variables

template <typename U>
static bool contains constexpr
Returns true if a given type appears in the list.
template <typename U>
static size_t index_of constexpr
Returns the index of the first appearance of a given type in the list.
static size_t length constexpr
The number of types in the list.

Typedef documentation

template <typename... T>
template <typename... U>
using muu::type_list::append = muu::type_list<T..., U...>

Creates a new type list by appending types to this one.

static_assert(std::is_same_v<
    muu::type_list<int, float, char>::append<double, void, bool>,
    muu::type_list<int, float, char, double, void, bool>
>);

template <typename... T>
using muu::type_list::first = /* ... */

The first type in the list.

using first_type = muu::type_list<int, float, char, void>::first;

std::cout << "is int:   " << std::is_same_v<first_type, int> << "\n";
std::cout << "is float: " << std::is_same_v<first_type, float> << "\n";
std::cout << "is char:  " << std::is_same_v<first_type, char> << "\n";
std::cout << "is void:  " << std::is_same_v<first_type, void> << "\n";
is int:   true
is float: false
is char:  false
is void:  false

template <typename... T>
using muu::type_list::flatten = /* ... */

A flattened version of the list with any nested type_lists recursively hoisted up into itself.

static_assert(std::is_same_v<
    muu::type_list<int, float, muu::type_list<muu::type_list<double>>>::flatten,
    muu::type_list<int, float, double>
>);

template <typename... T>
template <typename... U>
using muu::type_list::prepend = muu::type_list<U..., T...>

Creates a new type list by prepending types to this one.

static_assert(std::is_same_v<
    muu::type_list<int, float, char>::prepend<double, void, bool>,
    muu::type_list<double, void, bool, int, float, char>
>);

template <typename... T>
template <typename U>
using muu::type_list::remove = /* ... */

A version of the list with all ocurrences of the named type removed.

static_assert(std::is_same_v<
    muu::type_list<int, float, char, void, double, void>::remove<void>,
    muu::type_list<int, float, char, double>
>);

template <typename... T>
template <size_t Index>
using muu::type_list::select = /* ... */

Selects a single type from the list.

using selected_type = muu::type_list<int, float, char, void>::select<2>;

std::cout << "is int:   " << std::is_same_v<selected_type, int> << "\n";
std::cout << "is float: " << std::is_same_v<selected_type, float> << "\n";
std::cout << "is char:  " << std::is_same_v<selected_type, char> << "\n";
std::cout << "is void:  " << std::is_same_v<selected_type, void> << "\n";
is int:   false
is float: false
is char:  true
is void:  false

template <typename... T>
template <size_t Start, size_t Length = (length - Start)>
using muu::type_list::slice = /* ... */

Selects a slice of types from the list.

static_assert(std::is_same_v<
    muu::type_list<int, float, char, void>::slice<2, 2>,
    muu::type_list<char, void>
>);

template <typename... T>
using muu::type_list::type = first

Alias for first when length == 1.

Variable documentation

template <typename... T>
static size_t muu::type_list::length constexpr

The number of types in the list.

std::cout << muu::type_list<int, float, char, void>::length << "\n";
4