1 #ifndef SIPLASPLAS_UTILITY_FUSION_HPP 2 #define SIPLASPLAS_UTILITY_FUSION_HPP 6 #include "identity.hpp" 18 template<
typename Function,
typename Arg,
typename... Args>
19 void foreach(Function
function, Arg&& arg, Args&&... args)
22 (
function(std::forward<Arg>(arg)), 0),
23 (
function(std::forward<Args>(args)), 0)...
27 template<
typename Function>
28 void foreach(Function)
33 template<
typename Arg>
34 auto foreach(Arg&& arg)
36 return [arg](
auto function)
42 template<
typename Arg,
typename Arg2,
typename... Args>
43 auto foreach(Arg&& arg, Arg2&& arg2, Args&&... args)
45 return [arg, arg2, args...](
auto function)
47 ::cpp::detail::foreach(
function, arg, arg2, args...);
61 template<
typename T,
typename... Ts>
62 class TypesCall<
cpp::meta::list<T, Ts...>>
65 template<
typename Function>
66 static void apply_void(Function
function)
69 ::cpp::meta::identity<T>(),
70 ::cpp::meta::identity<Ts>()...
74 template<
typename U,
typename Function>
75 static std::vector<U> apply(Function
function)
78 ::cpp::meta::identity<T>(),
79 ::cpp::meta::identity<Ts>()...
83 template<
typename Function>
84 static auto apply(Function
function)
86 return std::make_tuple(
87 ::cpp::meta::identity<T>(),
88 ::cpp::meta::identity<Ts>()...
94 class TypesCall<
cpp::meta::list<>>
97 template<
typename Function>
98 static void apply_void(Function
function)
101 template<
typename T,
typename Function>
102 static std::vector<T> apply(Function
function)
107 template<
typename Function>
108 static auto apply(Function
function)
110 return std::make_tuple();
114 template<
typename... Ts>
115 class TypesCall<
cpp::meta::list<cpp::meta::list<Ts...>>> :
116 public TypesCall<meta::list<Ts...>>
120 template<
typename T,
typename... Ts,
typename Function>
121 std::vector<T> types_call(Function
function)
123 return TypesCall<cpp::meta::list<Ts...>>::template apply<T>(
function);
126 template<
typename... Ts,
typename Function>
127 void foreach_type(Function
function)
129 TypesCall<cpp::meta::list<Ts...>>::apply_void(
function);
132 template<
typename Function,
typename Previous>
133 auto fold(Function
function, Previous&& previous)
135 return std::forward<Previous>(previous);
138 template<
typename Function,
typename Previous,
typename Head,
typename... Tail>
139 auto fold(Function
function, Previous&& previous, Head&& head, Tail&&... tail)
144 std::forward<Previous>(previous),
145 std::forward<Head>(head)
147 std::forward<Tail>(tail)...
151 template<
typename T,
typename Function,
typename... Args>
152 std::vector<T> fmap(Function
function, Args&&... args)
154 return {
function(std::forward<Args>(args))...};
157 template<
typename T,
typename... Ts,
typename Function>
158 std::vector<T> fmap(Function
function)
160 return types_call<T, Ts...>(
function);
165 #endif // SIPLASPLAS_UTILITY_FUSION_HPP Definition: canary_allocator.hpp:7