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 traitmeta_result
. Represents the invoke result of a callable metafunction,TFunction
, with a metaprogramming type,TType
If
TFunction
is aMetaFunctionOf<TType>
, using aliases to the resulting type of invoking aTFunction
with aTType
. IfTFunction
is not aMetaFunctionOf<TType>
, the program is ill-formed.Requirements#
TFunction
must be aMetaFunctionOf<TType>
- 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 typeTType
is a metaprogramming value type.A metaprogramming value type is any type that has a
static constexpr
member variable namedvalue
.- 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 typeTType
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 typetype
(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 typeTType
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/orMetaValue
, representing each via the memberusing
aliasesfirst
andsecond
, respectively.TType
must have a memberusing
alias typefirst
(e.g.using type = bool;
).TType
must have a memberusing
alias typesecond
(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 typeTType
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 formtemplate<typename... TTypes> struct type { /‍** contents **‍/ };
- 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 namedvalue
.- 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 typetype
(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/orMetaValue
, representing each via the memberusing
aliasesfirst
andsecond
, respectively.TType
must have a memberusing
alias typefirst
(e.g.using type = bool;
).TType
must have a memberusing
alias typesecond
(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 formtemplate<typename... TTypes> struct type { /‍** contents **‍/ };
- 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 aMetaFunctionOf<TType>
, contains the member using alias type,type
, that is the resulting type of invoking aTFunction
with aTType
. IfTFunction
is not aMetaFunctionOf<TType>
, the program is ill-formed.Requirements#
TFunction
must be aMetaFunctionOf<TType>
- Template Parameters:
TFunction – The callable metafunction to get the invoke result of
TType – The metaprogramming type to invoke
TFunction
with
-
template<typename TFunction, typename TType>
-
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 namedvalue
.Requirements#
TType
must have astatic constexpr
member variable namedvalue
.
- 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 typetype
(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 astatic 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 astatic 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 aMetaType
or aMetaValue
- 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 ofMetaType
,MetaValue
, orMetaPair
metaprogramming type category and returns either aMetaType
or aMetaValue
- tparam TFunction:
The callable to check