Metaprogramming Type Categories (Concept Definitions)#

group metatypes

Hyperion provides concept and type trait definitions outlining the requirements for various categories of metaprogramming types.

Example#

#include <hyperion/mpl/metatypes.h>
#include <hyperion/mpl/value.h>
#include <hyperion/mpl/type.h>

using namespace hyperion::mpl;

struct not_meta {};

struct metatype {
    using type = void;
};

struct metavalue {
    static inline constexpr auto value = 42;
};

template<typename TType>
struct metatype_typefunction {
    using type = std::add_const_t<TType>;
};

template<typename TType>
struct metatype_valuefunction {
    static inline constexpr auto value = std::is_const_v<TType>;
};

template<auto TValue>
struct metavalue_typefunction {
    using type = std::conditional_t<TValue, int, void>;
};

template<auto TValue>
struct metavalue_valuefunction {
    static inline constexpr auto value = TValue * 2;
};

constexpr auto type_to_type = []([[maybe_unused]] const MetaType auto& type) -> Type<bool> {
    return {};
};
constexpr auto type_to_value
    = []([[maybe_unused]] const MetaType auto& type) -> Value<true> {
    return {};
};
constexpr auto value_to_type
    = []([[maybe_unused]] const MetaValue auto& type) -> Type<bool> {
    return {};
};
constexpr auto value_to_value
    = []([[maybe_unused]] const MetaValue auto& type) -> Value<true> {
    return {};
};

static_assert(MetaType<metatype>);
static_assert(not MetaType<not_meta>);

static_assert(MetaValue<metavalue>);
static_assert(not MetaValue<not_meta>);

static_assert(TypeMetaFunction<metatype_typefunction>);
static_assert(TypeMetaFunction<metatype_valuefunction>);

static_assert(ValueMetaFunction<metavalue_typefunction>);
static_assert(ValueMetaFunction<metavalue_valuefunction>);

static_assert(MetaFunction<decltype(type_to_type)>);
static_assert(MetaFunction<decltype(type_to_value)>);
static_assert(MetaFunction<decltype(value_to_type)>);
static_assert(MetaFunction<decltype(value_to_value)>);

Typedefs

template<typename TFunction, typename TType>
using meta_result_t = typename meta_result<TFunction, TType>::type#

Shorthand alias to the member using alias type, type, of the type trait meta_result. Represents the invoke result of a callable metafunction, TFunction, with a metaprogramming type, TType

If TFunction is a MetaFunctionOf<TType>, using aliases to the resulting type of invoking a TFunction with a TType. If TFunction is not a MetaFunctionOf<TType>, the program is ill-formed.

Requirements#

  • TFunction must be a MetaFunctionOf<TType>

    • It must be a callable invocable with TType

    • The result of invoking TFunction with TType must be either a MetaType or a MetaValue

Template Parameters:
  • TFunction – The callable metafunction to get the invoke result of

  • TType – The metaprogramming type to invoke TFunction with

Variables

template<typename TType>
static constexpr auto is_meta_value_v = is_meta_value<TType>::value#

Value of the type trait is_meta_value. Used to determine whether type TType is a metaprogramming value type.

A metaprogramming value type is any type that has a static constexpr member variable named value.

Template Parameters:

TType – The type to check

template<typename TType>
static constexpr auto is_meta_type_v = is_meta_type<TType>::value#

Value of the type trait is_meta_type. Used to determine whether type TType is a metaprogramming type wrapper type.

A metaprogramming type wrapper type is any type that represents another type, via a member using alias type type (e.g. using type = bool;).

Requirements#

  • TType must have a member using alias type type (e.g. using type = bool;).

Template Parameters:

TType – The type to check

template<typename TType>
static constexpr auto is_meta_pair_v = is_meta_pair<TType>::value#

Value of the type trait is_meta_pair. Used to determine whether type TType is a metaprogramming pair type.

A metaprogramming pair type is any type that represents a 2 element combination (a pair) of (potentially different) MetaType and/or MetaValue, representing each via the member using aliases first and second, respectively.

  • TType must have a member using alias type first (e.g. using type = bool;).

  • TType must have a member using alias type second (e.g. using type = bool;).

Template Parameters:

TType – The type to check

template<typename TType>
static constexpr auto is_meta_list_v = is_meta_list<TType>::value#

Value of the type trait is_meta_list. Used to determine whether type TType is a metaprogramming list type.

A metaprogramming list type is any type that represents a list of types and is not a MetaPair.

  • TType must be a class/struct template accepting a variadic list of types. I.E. it must be a type of the form template<typename... TTypes> struct type { /&zwj;** contents **&zwj;/ };

Template Parameters:

TType – The type to check

template<typename TType>
struct is_meta_value : public std::bool_constant<MetaValue<TType>>#
#include <hyperion/mpl/metatypes.h>

Type trait to determine whether type TType is a metaprogramming value type.

A metaprogramming value type is any type that has a static constexpr member variable named value.

Template Parameters:

TType – The type to check

template<typename TType>
struct is_meta_type : public std::bool_constant<MetaType<TType>>#
#include <hyperion/mpl/metatypes.h>

Type trait to determine whether type TType is a metaprogramming type wrapper type.

A metaprogramming type wrapper type is any type that represents another type, via a member using alias type type (e.g. using type = bool;).

Requirements#

  • TType must have a member using alias type type (e.g. using type = bool;).

Template Parameters:

TType – The type to check

template<typename TType>
struct is_meta_pair : public std::bool_constant<MetaPair<TType>>#
#include <hyperion/mpl/metatypes.h>

Type trait to determine whether type TType is a metaprogramming pair type.

A metaprogramming pair type is any type that represents a 2 element combination (a pair) of (potentially different) MetaType and/or MetaValue, representing each via the member using aliases first and second, respectively.

  • TType must have a member using alias type first (e.g. using type = bool;).

  • TType must have a member using alias type second (e.g. using type = bool;).

Template Parameters:

TType – The type to check

template<typename TType>
struct is_meta_list : public std::false_type#
#include <hyperion/mpl/metatypes.h>

Type trait to determine whether type TType is a metaprogramming list type.

A metaprogramming list type is any type that represents a list of types and is not a MetaPair.

  • TType must be a class/struct template accepting a variadic list of types. I.E. it must be a type of the form template<typename... TTypes> struct type { /&zwj;** contents **&zwj;/ };

Template Parameters:

TType – The type to check

template<typename TFunction, typename TType>
struct meta_result#
#include <hyperion/mpl/metatypes.h>

meta_result is a type trait representing the invoke result of a callable metafunction, TFunction, with a metaprogramming type, TType

If TFunction is a MetaFunctionOf<TType>, contains the member using alias type, type, that is the resulting type of invoking a TFunction with a TType. If TFunction is not a MetaFunctionOf<TType>, the program is ill-formed.

Requirements#

  • TFunction must be a MetaFunctionOf<TType>

    • It must be a callable invocable with TType

    • The result of invoking TFunction with TType must be either a MetaType or a MetaValue

Template Parameters:
  • TFunction – The callable metafunction to get the invoke result of

  • TType – The metaprogramming type to invoke TFunction with

template<typename TType>
concept MetaValue#
#include <hyperion/mpl/metatypes.h>

Concept specifying the requirements for a metaprogramming value type.

A metaprogramming value type is any type that has a static constexpr member variable named value.

Requirements#

  • TType must have a static constexpr member variable named value.

tparam TType:

The type to check

template<typename TType>
concept MetaType#
#include <hyperion/mpl/metatypes.h>

Concept specifying the requirements for a metaprogramming type wrapper type.

A metaprogramming type wrapper type is any type that represents another type, via a member using alias type type (e.g. using type = bool;).

Requirements#

  • TType must have a member using alias type type (e.g. using type = bool;).

tparam TType:

The type to check

template<template<auto> typename TTemplate>
concept ValueMetaFunction#
#include <hyperion/mpl/metatypes.h>

A TypeMetaFunction is a template metafunction that accepts a single value parameter and contains either a static constexpr member variable, value, or a member using alias type, type

tparam TTemplate:

The template to check

template<template<typename> typename TTemplate>
concept TypeMetaFunction#
#include <hyperion/mpl/metatypes.h>

A TypeMetaFunction is a template metafunction that accepts a single type parameter and contains either a static constexpr member variable, value, or a member using alias type, type

tparam TTemplate:

The template to check

template<typename TFunction, typename TType>
concept MetaFunctionOf#
#include <hyperion/mpl/metatypes.h>

A MetaFunctionOf is a callable metafunction that accepts a single value parameter of the specified type, TType and returns either a MetaType or a MetaValue

tparam TFunction:

The callable to check

tparam TType:

The metaprogramming type to check that TFunction is invocable with

template<typename TFunction>
concept MetaFunction#
#include <hyperion/mpl/metatypes.h>

A MetaFunction is a callable metafunction that accepts a single value parameter of MetaType, MetaValue, or MetaPair metaprogramming type category and returns either a MetaType or a MetaValue

tparam TFunction:

The callable to check