OGS
BaseLib::TMP Namespace Reference

Namespaces

namespace  detail
 

Classes

struct  Concat
 
struct  Concat< List< Types1... >, List< Types2... > >
 
struct  List
 A list of types. More...
 
struct  Map
 
struct  Map< MapFromTypeToType, List< Types... > >
 

Typedefs

template<typename List1 , typename List2 >
using Concat_t = typename Concat<List1, List2>::type
 
template<template< typename > typename MapFromTypeToType, typename List >
using Map_t = typename Map<MapFromTypeToType, List>::type
 

Functions

template<typename List , typename Pred >
decltype(auto) filter (Pred pred)
 
template<typename List , typename Function >
constexpr decltype(auto) map_to_array (Function &&f)
 
template<typename List , typename Function >
void foreach (Function &&f)
 
template<typename List , typename Type >
constexpr bool contains ()
 Returns if Type is contained in the given List of types.
 

Typedef Documentation

◆ Concat_t

template<typename List1 , typename List2 >
using BaseLib::TMP::Concat_t = typename Concat<List1, List2>::type

Concatenates two lists of types.

Definition at line 37 of file TMP.h.

◆ Map_t

template<template< typename > typename MapFromTypeToType, typename List >
using BaseLib::TMP::Map_t = typename Map<MapFromTypeToType, List>::type

Turns a list of types into a list of different types via the provided type mapping.

Definition at line 102 of file TMP.h.

Function Documentation

◆ contains()

template<typename List , typename Type >
constexpr bool BaseLib::TMP::contains ( )
constexpr

Returns if Type is contained in the given List of types.

Definition at line 165 of file TMP.h.

166{
167 auto pred_is_same = []<typename OtherType>(OtherType*)
168 { return std::is_same_v<Type, OtherType>; };
169
170 return any_of(map_to_array<List>(pred_is_same));
171}
constexpr bool any_of(List const &values)
Checks if any of the elements in the given list is true.
Definition Algorithm.h:276

References BaseLib::any_of().

◆ filter()

template<typename List , typename Pred >
decltype(auto) BaseLib::TMP::filter ( Pred pred)

Filters the given list of types via the given predicate.

Keeps all elements for which pred is true.

The function signature of pred should be bool pred(Type*), where Type is a member of the given list of types.

Definition at line 78 of file TMP.h.

79{
80 return detail::filter(pred, static_cast<List*>(nullptr));
81}
A list of types.
Definition TMP.h:43

References BaseLib::TMP::detail::filter().

Referenced by BaseLib::TMP::detail::filter().

◆ foreach()

template<typename List , typename Function >
void BaseLib::TMP::foreach ( Function && f)

Applies the given function to a list of types.

The function signature should be void f(Type*), where Type is a member of the given list of types.

Definition at line 157 of file TMP.h.

158{
159 detail::foreach (std::forward<Function>(f), (List*)nullptr);
160}

References BaseLib::TMP::detail::foreach().

◆ map_to_array()

template<typename List , typename Function >
constexpr decltype(auto) BaseLib::TMP::map_to_array ( Function && f)
constexpr

Applies the given function to a list of types returning the array of results.

The function signature should be ReturnType f(Type*), where Type is a member of the given list of types and ReturnType is the same for all overloads of f.

Definition at line 134 of file TMP.h.

135{
136 return detail::map_to_array(std::forward<Function>(f), (List*)nullptr);
137}

References BaseLib::TMP::detail::map_to_array().