1 #ifndef SIPLASPLAS_UTILITY_FUSION_HPP 2 #define SIPLASPLAS_UTILITY_FUSION_HPP 11 #include <ctti/type_id.hpp> 20 class DefaultConstructible
23 constexpr DefaultConstructible() =
default;
28 template<
typename Function,
typename Arg,
typename... Args>
29 void foreach(Function
function, Arg&& arg, Args&&... args)
32 (
function(std::forward<Arg>(arg)), 0),
33 (
function(std::forward<Args>(args)), 0)...
37 template<
typename Function>
38 void foreach(Function)
43 template<
typename Arg>
44 auto foreach(Arg&& arg)
46 return [arg](
auto function)
52 template<
typename Arg,
typename Arg2,
typename... Args>
53 auto foreach(Arg&& arg, Arg2&& arg2, Args&&... args)
55 return [arg, arg2, args...](
auto function)
57 ::cpp::detail::foreach(
function, arg, arg2, args...);
71 template<
typename T,
typename... Ts>
72 class TypesCall<
cpp::meta::list<T, Ts...>>
75 template<
typename Function>
76 static void apply_void(Function
function)
79 detail::DefaultConstructible<T>(),
80 detail::DefaultConstructible<Ts>()...
84 template<
typename U,
typename Function>
85 static std::vector<U> apply(Function
function)
88 function(detail::DefaultConstructible<T>()),
89 function(detail::DefaultConstructible<Ts>())...
93 template<
typename Function>
94 static auto apply(Function
function)
96 return std::make_tuple(
97 function(detail::DefaultConstructible<T>()),
98 function(detail::DefaultConstructible<Ts>())...
104 class TypesCall<
cpp::meta::list<>>
107 template<
typename Function>
108 static void apply_void(Function
function)
111 template<
typename T,
typename Function>
112 static std::vector<T> apply(Function
function)
117 template<
typename Function>
118 static auto apply(Function
function)
120 return std::make_tuple();
124 template<
typename... Ts>
125 class TypesCall<
cpp::meta::list<cpp::meta::list<Ts...>>> :
126 public TypesCall<meta::list<Ts...>>
130 template<
typename T,
typename... Ts,
typename Function>
131 std::vector<T> types_call(Function
function)
133 return TypesCall<cpp::meta::list<Ts...>>::template apply<T>(
function);
136 template<
typename... Ts,
typename Function>
137 void foreach_type(Function
function)
139 TypesCall<cpp::meta::list<Ts...>>::apply_void(
function);
142 template<
typename Function,
typename Previous>
143 auto fold(Function
function, Previous&& previous)
145 return std::forward<Previous>(previous);
148 template<
typename Function,
typename Previous,
typename Head,
typename... Tail>
149 auto fold(Function
function, Previous&& previous, Head&& head, Tail&&... tail)
154 std::forward<Previous>(previous),
155 std::forward<Head>(head)
157 std::forward<Tail>(tail)...
161 template<
typename T,
typename Function,
typename... Args>
162 std::vector<T> fmap(Function
function, Args&&... args)
164 return {
function(std::forward<Args>(args))...};
167 template<
typename T,
typename... Ts,
typename Function>
168 std::vector<T> fmap(Function
function)
170 return types_call<T, Ts...>(
function);
173 template<
typename Types>
174 std::string printTypeList()
176 std::ostringstream os;
180 foreach<Types>([&os](
auto type)
182 os << ctti::type_id<typename decltype(type)::type>().name() <<
", ";
192 #endif // SIPLASPLAS_UTILITY_FUSION_HPP Definition: canary_allocator.hpp:7