|
27 | 27 |
|
28 | 28 | constexpr double ERROR_TOLERANCE = 1e-5;
|
29 | 29 |
|
30 |
| -// Typed call helper |
31 |
| -// Iterates over all types and calls Functor f for each of them |
32 |
| -template <typename Functor, template <typename...> class Container, |
33 |
| - typename... Ts> |
34 |
| -void for_each_type_call(Functor &&f, Container<Ts...> *) { |
35 |
| - (f.template operator()<Ts>(), ...); |
| 30 | +template <typename Tuple, typename Func, std::size_t... Is> |
| 31 | +void for_each_type_call(Func &&f, std::index_sequence<Is...>) { |
| 32 | + (f(std::integral_constant<std::size_t, Is>{}), ...); |
36 | 33 | }
|
37 | 34 |
|
38 |
| -template <typename tuple, typename Functor> |
39 |
| -void instantiate_all_types(Functor &&f) { |
40 |
| - for_each_type_call(f, static_cast<tuple *>(nullptr)); |
| 35 | +template <typename Tuple, typename Func> void instantiate_all_types(Func &&f) { |
| 36 | + for_each_type_call<Tuple>( |
| 37 | + std::forward<Func>(f), |
| 38 | + std::make_index_sequence<std::tuple_size_v<Tuple>>{}); |
41 | 39 | }
|
42 | 40 |
|
43 | 41 | #define INSTANTIATE_ALL_TYPES(tuple, f) \
|
44 |
| - instantiate_all_types<tuple>([]<typename T>() { f<T>(); }); |
| 42 | + instantiate_all_types<tuple>([](auto index) { \ |
| 43 | + using T = std::tuple_element_t<decltype(index)::value, tuple>; \ |
| 44 | + f<T>(); \ |
| 45 | + }); |
45 | 46 |
|
46 | 47 | using value_type_list =
|
47 | 48 | std::tuple<int, unsigned int, short, unsigned short, long, unsigned long,
|
|
0 commit comments