CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
TypeListOps.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include "Concat.hpp"
11#include "Map.hpp"
12#include "MetaFor.hpp"
13#include "Rename.hpp"
14#include "Type.hpp"
15#include "TypeList.hpp"
16
17#include <tuple>
18#include <type_traits>
19
20namespace CeresEngine::MPL {
21
23 template<typename TTypeList> using Tuple = Rename<std::tuple, TTypeList>;
24
26 template<typename TTypeList> using TypeTuple = Tuple<Map<Type, TTypeList>>;
27
29 template<std::size_t TIndex, typename TTypeList> using Nth = std::tuple_element_t<TIndex, Tuple<TTypeList>>;
30
32 template<typename T, typename TTypeList> using PushBack = Concat<TTypeList, TypeList<T>>;
33
35 template<typename T, typename TTypeList> using PushFront = Concat<TypeList<T>, TTypeList>;
36
38 template<typename TTypeList> constexpr auto size() noexcept { return TTypeList::size; }
39
42 template<typename TTypeList, typename TFunction> constexpr void forTypes(TFunction&& mFunction) noexcept { forTuple(mFunction, TypeTuple<TTypeList>{}); }
43
45 template<typename TTypeList> using Head = Nth<0, TTypeList>;
46
48 template<typename TTypeList> using Tail = Nth<size<TTypeList>() - 1, TTypeList>;
49
50 struct ExpandT {
51 ExpandT(std::initializer_list<int>&&) {}
52 };
53#define EXPAND(CODE) CeresEngine::MPL::ExpandT{0, ((CODE), 0)...};
54
55} // namespace CeresEngine::MPL
Definition All.hpp:15
Concat< TTypeList, TypeList< T > > PushBack
Adds a type to the back of a type list.
Definition TypeListOps.hpp:32
Rename< std::tuple, TTypeList > Tuple
Type list as a tuple.
Definition TypeListOps.hpp:23
Concat< TypeList< T >, TTypeList > PushFront
Adds a type to the front of a type list.
Definition TypeListOps.hpp:35
typename ConcatHelper< TTypeLists... >::type Concat
Interface type alias.
Definition Concat.hpp:20
typename RenameHelper< TNewName, T >::type Rename
Definition Rename.hpp:19
constexpr decltype(auto) forTuple(TFunction &&function, TTuple &&tuple)
Definition MetaFor.hpp:29
Tuple< Map< Type, TTypeList > > TypeTuple
Type list as a tuple of Type<T>.
Definition TypeListOps.hpp:26
Nth< size< TTypeList >() - 1, TTypeList > Tail
Last type of a type list.
Definition TypeListOps.hpp:48
std::tuple_element_t< TIndex, Tuple< TTypeList > > Nth
"Nth" element of a type list.
Definition TypeListOps.hpp:29
Nth< 0, TTypeList > Head
First type of a type list.
Definition TypeListOps.hpp:45
constexpr auto size() noexcept
Size of a type list.
Definition TypeListOps.hpp:38
constexpr void forTypes(TFunction &&mFunction) noexcept
Execute a function for every type in a type list, wrapped in a Type<T>.
Definition TypeListOps.hpp:42
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Definition TypeListOps.hpp:50
ExpandT(std::initializer_list< int > &&)
Definition TypeListOps.hpp:51