MCRO
C++23 utilities for Unreal Engine.
Loading...
Searching...
No Matches
Templates.h File Reference
#include "CoreMinimal.h"
#include "Mcro/Macros.h"
#include "Mcro/Concepts.h"

Go to the source code of this file.

Data Structures

struct  Mcro::Templates::Detail::TTypeAtPack_Impl< I, First, Rest >
 
struct  Mcro::Templates::Detail::TTypeAtPack_Impl< 0, First, Rest... >
 
struct  Mcro::Templates::TTypeAtPack_Struct< I, T >
 
struct  Mcro::Templates::TTypeAtPack_Struct< I >
 
struct  Mcro::Templates::TTupleSafeElement_Struct< I, T >
 
struct  Mcro::Templates::TTupleSafeElement_Struct< I, TTuple< T... > >
 
struct  Mcro::Templates::TTypes< T >
 This template is used to store pack of types in other templates, or to allow parameter pack inference for functions. This template may be referred to as 'type-list' in other parts of the documentation. More...
 
struct  Mcro::Templates::TIsTypeList_Struct< T >
 
struct  Mcro::Templates::TIsTypeList_Struct< TTypes< T... > >
 
struct  Mcro::Templates::TTypesSkip_Struct< Count, T >
 
struct  Mcro::Templates::TTypesTrimEnd_Struct< Count, T >
 
struct  Mcro::Templates::TTypesTake_Struct< Count, T >
 
struct  Mcro::Templates::TTemplate_Match< Template >
 Base struct for matching templates disregarding their arguments. More...
 
struct  Mcro::Templates::TTemplate_Struct< typename >
 
struct  Mcro::Templates::TTemplate_Struct< Template< Params... > >
 Base struct containing traits of specified template instance (which only accepts type parameters) More...
 
struct  Mcro::Templates::TTemplateMap_Struct< typename, typename >
 
struct  Mcro::Templates::TTemplateMap_Struct< TemplateOut, TemplateIn< Params... > >
 

Namespaces

namespace  Mcro
 
namespace  Mcro::Templates
 This namespace provides templating utilities and introspection into template instantiations.
 
namespace  Mcro::Templates::Detail
 

Concepts

concept  Mcro::Templates::CTypeList
 Concept constraining a given type to TTypes
 
concept  Mcro::Templates::CTypesConvertibleTo
 Is given type-list contains all types convertible to the types of another type-list. The number and order of types are significant.
 
concept  Mcro::Templates::CTypesConvertibleToDecayed
 Is given type-list contains all types convertible to the types of another type-list. The number and order of types are significant. Qualifiers are not taken into account.
 
concept  Mcro::Templates::CTypeOnlyTemplate
 Checks if input is a template which only has type parameters.
 
concept  Mcro::Templates::CMatchTemplate
 Check if given type is an instantiation of a given template (which only accepts type parameters)
 

Macros

#define MCRO_TYPE_LIST_PREDICATE(Function, TypeList, OnEmpty, ...)
 
#define ALL_OF_TYPE_LIST(typeList, onEmpty, ...)
 Apply an arbitrary predicate to all types in a type-list, All must pass.
 
#define C_ALL_OF_TYPE_LIST(typeList, onEmpty, conceptIn, ...)
 Apply a concept to all types in a type-list, All must pass. If a concept needs extra template arguments you can provide them as variadic macro arguments.
 
#define ANY_OF_TYPE_LIST(typeList, onEmpty, ...)
 Apply an arbitrary predicate to all types in a type-list, Any of them can pass.
 
#define C_ANY_OF_TYPE_LIST(typeList, onEmpty, conceptIn, ...)
 Apply a concept to all types in a type-list, Any of them can pass. If a concept needs extra template arguments you can provide them as variadic macro arguments.
 
#define ALL_OF_TYPE_PACK(TypePack, onEmpty, ...)
 Apply an arbitrary predicate to all types in input type parameter pack, All must pass.
 
#define C_ALL_OF_TYPE_PACK(TypePack, onEmpty, conceptIn, ...)
 Apply a concept to all types in input type parameter pack, All must pass. If a concept needs extra template arguments you can provide them as variadic macro arguments.
 
#define ANY_OF_TYPE_PACK(TypePack, onEmpty, ...)
 Apply an arbitrary predicate to all types in input type parameter pack, Any of them can pass.
 
#define C_ANY_OF_TYPE_PACK(TypePack, onEmpty, conceptIn, ...)
 Apply a concept to all types in input type parameter pack, Any of them can pass. If a concept needs extra template arguments you can provide them as variadic macro arguments.
 

Typedefs

template<size_t I, typename... Rest>
using Mcro::Templates::TTypeAtPack = typename TTypeAtPack_Struct<I, Rest...>::Type
 Get a specific item from a parameter pack at given index. It is an unspecified compile error to index an empty parameter pack.
 
template<size_t I, typename... Rest>
using Mcro::Templates::TLastTypeAtPack = typename TTypeAtPack_Struct<sizeof...(Rest) - I - 1, Rest...>::Type
 Get a specific item from the end of a parameter pack at given index (0 == last). It is an unspecified compile error to index an empty parameter pack.
 
template<size_t I, typename... Rest>
using Mcro::Templates::TTypeAtPackDecay = std::decay_t<typename TTypeAtPack_Struct<I, Rest...>::Type>
 Get a specific item from a parameter pack at given index disregarding CV-ref qualifiers. It is an unspecified compile error to index an empty parameter pack.
 
template<size_t I, typename... Rest>
using Mcro::Templates::TLastTypeAtPackDecay = std::decay_t<typename TTypeAtPack_Struct<sizeof...(Rest) - I - 1, Rest...>::Type>
 Get a specific item from the end of a parameter pack at given index (0 == last) disregarding CV-ref qualifiers. It is an unspecified compile error to index an empty parameter pack.
 
template<CTypeList T, size_t I>
using Mcro::Templates::TTypes_Get = T::template Get<I>
 
template<CTypeList T, size_t I>
using Mcro::Templates::TTypes_GetDecay = T::template GetDecay<I>
 
template<CTypeList T, size_t... Indices>
using Mcro::Templates::TComposeTypeListFrom = TTypes<TTypes_Get<T, Indices>...>
 
template<size_t Count, CTypeList T>
using Mcro::Templates::TTypesSkip = typename TTypesSkip_Struct<Count, T>::Type
 
template<size_t Count, typename T >
using Mcro::Templates::TTypesTrimEnd = typename TTypesTrimEnd_Struct<Count, T>::Type
 
template<size_t Count, typename T >
using Mcro::Templates::TTypesTake = typename TTypesTake_Struct<Count, T>::Type
 
template<CTypeOnlyTemplate Instance>
using Mcro::Templates::TTemplate_Params = typename TTemplate_Struct<Instance>::Parameters
 Get template type parameters as a tuple.
 
template<CTypeOnlyTemplate Instance>
using Mcro::Templates::TTemplate_ParamsDecay = typename TTemplate_Struct<Instance>::ParametersDecay
 Get decayed template type parameters as a tuple.
 
template<CTypeOnlyTemplate Instance, int I>
using Mcro::Templates::TTemplate_Param = typename TTemplate_Struct<Instance>::template Param<I>
 Get a type parameter at a specified position of a templated instance.
 
template<CTypeOnlyTemplate Instance, int I>
using Mcro::Templates::TTemplate_ParamDecay = typename TTemplate_Struct<Instance>::template ParamDecay<I>
 Get a decayed type parameter at a specified position of a templated instance.
 
template<template< typename... > typename TemplateOut, CTypeOnlyTemplate FromInstance>
using Mcro::Templates::TTemplateMap = typename TTemplateMap_Struct<TemplateOut, FromInstance>::Type
 Transfer parameters from one template to another. Or in other words replace the template part of the input template instance with TemplateOut.
 

Functions

template<CTypeList TypeList, auto Test, size_t... Indices>
consteval bool Mcro::Templates::Detail::AllOfTypeList (bool onEmpty, std::index_sequence< Indices... > &&)
 
template<CTypeList TypeList, auto Test, size_t... Indices>
consteval bool Mcro::Templates::Detail::AllOfTypeListDecay (bool onEmpty, std::index_sequence< Indices... > &&)
 
template<CTypeList TypeList, auto Test, size_t... Indices>
consteval bool Mcro::Templates::Detail::AnyOfTypeList (bool onEmpty, std::index_sequence< Indices... > &&)
 
template<CTypeList TypeList, auto Test, size_t... Indices>
consteval bool Mcro::Templates::Detail::AnyOfTypeListDecay (bool onEmpty, std::index_sequence< Indices... > &&)
 
template<CTypeList From, CTypeList To, size_t... Indices>
consteval bool Mcro::Templates::Detail::IsTypeListConvertibleTo (bool onEmpty, std::index_sequence< Indices... > &&)
 
template<CTypeList From, CTypeList To, size_t... Indices>
consteval bool Mcro::Templates::Detail::IsTypeListConvertibleToDecay (bool onEmpty, std::index_sequence< Indices... > &&)
 
template<CConstType T>
constexpr auto && Mcro::Templates::AsConst (T &&input)
 Tired of typing const_cast<FMyLongUnwieldyTypeName>(...)? use this instead.
 
template<CMutableType T>
constexpr auto && Mcro::Templates::AsMutable (T &&input)
 Tired of typing const_cast<FMyLongUnwieldyTypeName>(...)? use this instead.
 
template<typename T >
constexpr auto Mcro::Templates::AsConstPtr (const T *input)
 Tired of typing const_cast<FMyLongUnwieldyTypeName*>(...)? use this instead.
 
template<typename T >
constexpr auto Mcro::Templates::AsConstPtr (T *input)
 Tired of typing const_cast<FMyLongUnwieldyTypeName*>(...)? use this instead.
 
template<typename T >
constexpr auto Mcro::Templates::AsMutablePtr (T *input)
 Tired of typing const_cast<FMyLongUnwieldyTypeName*>(...)? use this instead.
 
template<typename T >
constexpr auto Mcro::Templates::AsMutablePtr (const T *input)
 Tired of typing const_cast<FMyLongUnwieldyTypeName*>(...)? use this instead.
 

Variables

template<CTypeOnlyTemplate Instance>
constexpr size_t Mcro::Templates::TTemplate_ParamCount = TTemplate_Struct<Instance>::ParameterCount
 Get the number of template type parameters from a specified templated instance (which only has type parameters)
 

Detailed Description

Author
David Mórász
Date
2025

Definition in file Templates.h.

Macro Definition Documentation

◆ ALL_OF_TYPE_LIST

#define ALL_OF_TYPE_LIST ( typeList,
onEmpty,
... )
Value:
MCRO_TYPE_LIST_PREDICATE(Detail::AllOfTypeList, typeList, onEmpty, __VA_ARGS__)
#define MCRO_TYPE_LIST_PREDICATE(Function, TypeList, OnEmpty,...)
Definition Templates.h:259

Apply an arbitrary predicate to all types in a type-list, All must pass.

Parameters
typeListInput typelist
onEmptyDefault value if type-list is empty

Definition at line 272 of file Templates.h.

◆ ALL_OF_TYPE_PACK

#define ALL_OF_TYPE_PACK ( TypePack,
onEmpty,
... )
Value:
ALL_OF_TYPE_LIST(TTypes<TypePack...>, onEmpty, __VA_ARGS__)
#define ALL_OF_TYPE_LIST(typeList, onEmpty,...)
Apply an arbitrary predicate to all types in a type-list, All must pass.
Definition Templates.h:272

Apply an arbitrary predicate to all types in input type parameter pack, All must pass.

Parameters
typeListinput type parameter pack without ...
onEmptyDefault value if type parameter pack is empty

Definition at line 312 of file Templates.h.

◆ ANY_OF_TYPE_LIST

#define ANY_OF_TYPE_LIST ( typeList,
onEmpty,
... )
Value:
MCRO_TYPE_LIST_PREDICATE(Detail::AnyOfTypeList, typeList, onEmpty, __VA_ARGS__)

Apply an arbitrary predicate to all types in a type-list, Any of them can pass.

Parameters
typeListInput typelist
onEmptyDefault value if type-list is empty

Definition at line 292 of file Templates.h.

◆ ANY_OF_TYPE_PACK

#define ANY_OF_TYPE_PACK ( TypePack,
onEmpty,
... )
Value:
ANY_OF_TYPE_LIST(TTypes<TypePack...>, onEmpty, __VA_ARGS__)
#define ANY_OF_TYPE_LIST(typeList, onEmpty,...)
Apply an arbitrary predicate to all types in a type-list, Any of them can pass.
Definition Templates.h:292

Apply an arbitrary predicate to all types in input type parameter pack, Any of them can pass.

Parameters
typeListinput type parameter pack without ...
onEmptyDefault value if type parameter pack is empty

Definition at line 332 of file Templates.h.

◆ C_ALL_OF_TYPE_LIST

#define C_ALL_OF_TYPE_LIST ( typeList,
onEmpty,
conceptIn,
... )
Value:
ALL_OF_TYPE_LIST(typeList, onEmpty, conceptIn<T __VA_OPT__(,) __VA_ARGS__>)

Apply a concept to all types in a type-list, All must pass. If a concept needs extra template arguments you can provide them as variadic macro arguments.

Parameters
TypeListInput typelist
onEmptyDefault value if type-list is empty
conceptInThe given concept to check for all items in the typeList

Definition at line 283 of file Templates.h.

◆ C_ALL_OF_TYPE_PACK

#define C_ALL_OF_TYPE_PACK ( TypePack,
onEmpty,
conceptIn,
... )
Value:
C_ALL_OF_TYPE_LIST(TTypes<TypePack...>, onEmpty, conceptIn, __VA_ARGS__)
#define C_ALL_OF_TYPE_LIST(typeList, onEmpty, conceptIn,...)
Apply a concept to all types in a type-list, All must pass. If a concept needs extra template argumen...
Definition Templates.h:283

Apply a concept to all types in input type parameter pack, All must pass. If a concept needs extra template arguments you can provide them as variadic macro arguments.

Parameters
typeListinput type parameter pack without ...
onEmptyDefault value if type parameter pack is empty
conceptInThe given concept to check for all items in the type parameter pack

Definition at line 323 of file Templates.h.

◆ C_ANY_OF_TYPE_LIST

#define C_ANY_OF_TYPE_LIST ( typeList,
onEmpty,
conceptIn,
... )
Value:
ANY_OF_TYPE_LIST(typeList, onEmpty, conceptIn<T __VA_OPT__(,) __VA_ARGS__>)

Apply a concept to all types in a type-list, Any of them can pass. If a concept needs extra template arguments you can provide them as variadic macro arguments.

Parameters
TypeListInput typelist
onEmptyDefault value if type-list is empty
conceptInThe given concept to check for all items in the typeList

Definition at line 303 of file Templates.h.

◆ C_ANY_OF_TYPE_PACK

#define C_ANY_OF_TYPE_PACK ( TypePack,
onEmpty,
conceptIn,
... )
Value:
C_ANY_OF_TYPE_LIST(TTypes<TypePack...>, onEmpty, conceptIn, __VA_ARGS__)
#define C_ANY_OF_TYPE_LIST(typeList, onEmpty, conceptIn,...)
Apply a concept to all types in a type-list, Any of them can pass. If a concept needs extra template ...
Definition Templates.h:303

Apply a concept to all types in input type parameter pack, Any of them can pass. If a concept needs extra template arguments you can provide them as variadic macro arguments.

Parameters
typeListinput type parameter pack without ...
onEmptyDefault value if type parameter pack is empty
conceptInThe given concept to check for all items in the type parameter pack

Definition at line 343 of file Templates.h.

◆ MCRO_TYPE_LIST_PREDICATE

#define MCRO_TYPE_LIST_PREDICATE ( Function,
TypeList,
OnEmpty,
... )
Value:
Function< \
BOOST_PP_REMOVE_PARENS(TypeList), \
[] <typename T> (TTypes<T>&&) { return __VA_ARGS__; } \
>(OnEmpty, std::make_index_sequence<BOOST_PP_REMOVE_PARENS(TypeList)::Count>())

Definition at line 259 of file Templates.h.