Skip to content

Commit 02eff22

Browse files
committed
Fix for_each.
1 parent 9bc2e85 commit 02eff22

File tree

1 file changed

+12
-25
lines changed

1 file changed

+12
-25
lines changed

typelist.hpp

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,6 @@ struct type_list_item
1717
static constexpr const uint64_t index = index_;
1818
};
1919

20-
// for_each
21-
template<typename Func, uint64_t index, typename T, typename... TS>
22-
void _for_each_impl(const Func& func)
23-
{
24-
func(type_list_item<T, index>());
25-
_for_each_impl<Func, index + 1, TS...>(func);
26-
}
27-
28-
template<typename Func, uint64_t index>
29-
void _for_each_impl(const Func&)
30-
{}
31-
32-
// instantiate
33-
template<typename Func, uint64_t index, typename T, typename... TS>
34-
void _instantiate_impl(const Func& func)
35-
{
36-
func(type_list_item<T, index>());
37-
_for_each_impl<Func, index + 1, TS...>(func);
38-
}
39-
40-
template<typename Func, uint64_t index>
41-
void _instantiate_impl(const Func&)
42-
{}
43-
4420
// get
4521
template<uint64_t index, typename T, typename... TS>
4622
struct _get_nth_type_inner;
@@ -140,10 +116,21 @@ struct type_list
140116
using keep = typename _keep_impl<type_list<TS...>, indices...>::type;
141117

142118
// Runtime operations
119+
template<typename Func>
120+
static void _for_each_helper(const Func& func)
121+
{
122+
// FIXME: so ugly :(
123+
auto wrapper = [&](auto t) {
124+
func(t);
125+
return 1;
126+
};
127+
std::make_tuple(wrapper(TS())...);
128+
}
129+
143130
template<typename Func>
144131
static void for_each(const Func& func)
145132
{
146-
_for_each_impl<Func, 0, TS...>(func);
133+
enumerate::template _for_each_helper<Func>(func);
147134
}
148135

149136
template<template<typename...> class U, typename Func>

0 commit comments

Comments
 (0)