1 #ifndef SIPLASPLAS_UTILITY_FUSION_HPP 2 #define SIPLASPLAS_UTILITY_FUSION_HPP 18 class DefaultConstructible
21 constexpr DefaultConstructible() =
default;
26 template<
typename Function,
typename Arg,
typename... Args>
27 void foreach(Function
function, Arg&& arg, Args&&... args)
30 (
function(std::forward<Arg>(arg)), 0),
31 (
function(std::forward<Args>(args)), 0)...
35 template<
typename Function>
36 void foreach(Function)
41 template<
typename Arg>
42 auto foreach(Arg&& arg)
44 return [arg](
auto function)
50 template<
typename Arg,
typename Arg2,
typename... Args>
51 auto foreach(Arg&& arg, Arg2&& arg2, Args&&... args)
53 return [arg, arg2, args...](
auto function)
55 ::cpp::detail::foreach(
function, arg, arg2, args...);
69 template<
typename T,
typename... Ts>
70 class TypesCall<
cpp::meta::list<T, Ts...>>
73 template<
typename Function>
74 static void apply_void(Function
function)
77 detail::DefaultConstructible<T>(),
78 detail::DefaultConstructible<Ts>()...
82 template<
typename U,
typename Function>
83 static std::vector<U> apply(Function
function)
86 function(detail::DefaultConstructible<T>()),
87 function(detail::DefaultConstructible<Ts>())...
91 template<
typename Function>
92 static auto apply(Function
function)
94 return std::make_tuple(
95 function(detail::DefaultConstructible<T>()),
96 function(detail::DefaultConstructible<Ts>())...
102 class TypesCall<
cpp::meta::list<>>
105 template<
typename Function>
106 static void apply_void(Function
function)
109 template<
typename T,
typename Function>
110 static std::vector<T> apply(Function
function)
115 template<
typename Function>
116 static auto apply(Function
function)
118 return std::make_tuple();
122 template<
typename... Ts>
123 class TypesCall<
cpp::meta::list<cpp::meta::list<Ts...>>> :
124 public TypesCall<meta::list<Ts...>>
128 template<
typename T,
typename... Ts,
typename Function>
129 std::vector<T> types_call(Function
function)
131 return TypesCall<cpp::meta::list<Ts...>>::template apply<T>(
function);
134 template<
typename... Ts,
typename Function>
135 void foreach_type(Function
function)
137 TypesCall<cpp::meta::list<Ts...>>::apply_void(
function);
140 template<
typename Function,
typename Previous>
141 auto fold(Function
function, Previous&& previous)
143 return std::forward<Previous>(previous);
146 template<
typename Function,
typename Previous,
typename Head,
typename... Tail>
147 auto fold(Function
function, Previous&& previous, Head&& head, Tail&&... tail)
152 std::forward<Previous>(previous),
153 std::forward<Head>(head)
155 std::forward<Tail>(tail)...
159 template<
typename T,
typename Function,
typename... Args>
160 std::vector<T> fmap(Function
function, Args&&... args)
162 return {
function(std::forward<Args>(args))...};
165 template<
typename T,
typename... Ts,
typename Function>
166 std::vector<T> fmap(Function
function)
168 return types_call<T, Ts...>(
function);
173 #endif // SIPLASPLAS_UTILITY_FUSION_HPP Definition: canary_allocator.hpp:7