EntityComponentMetaSystem
An implementation of an EntityComponent System with template meta-programming.
Loading...
Searching...
No Matches
ForEachWithIndex.hpp
1
2// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed
3// under the Academic Free License.
4// His code is available here: https://github.com/SuperV1234/cppcon2015
5
6
7#ifndef EC_META_FOR_EACH_WITH_INDEX_HPP
8#define EC_META_FOR_EACH_WITH_INDEX_HPP
9
10#include <tuple>
11#include <utility>
12#include "Morph.hpp"
13
14namespace EC
15{
16 namespace Meta
17 {
18 template <typename Function, typename TTuple, std::size_t... Indices>
19 constexpr void forEachWithIndexHelper(
20 Function&& function, TTuple tuple, std::index_sequence<Indices...>)
21 {
22 return (void)std::initializer_list<int>{(function(std::move(
23 std::get<Indices>(tuple)), Indices), 0)...};
24 }
25
26 template <typename TTypeList, typename Function>
27 constexpr void forEachWithIndex(Function&& function)
28 {
29 using TTuple = EC::Meta::Morph<TTypeList, std::tuple<> >;
30 using TTupleSize = std::tuple_size<TTuple>;
31 using IndexSeq = std::make_index_sequence<TTupleSize::value>;
32
33 return forEachWithIndexHelper(
34 std::forward<Function>(function), TTuple{}, IndexSeq{});
35 }
36 }
37}
38
39#endif
40