aboutsummaryrefslogtreecommitdiff
path: root/src/function/detail
diff options
context:
space:
mode:
Diffstat (limited to 'src/function/detail')
-rw-r--r--src/function/detail/apply.h86
1 files changed, 86 insertions, 0 deletions
diff --git a/src/function/detail/apply.h b/src/function/detail/apply.h
new file mode 100644
index 0000000..bf60be1
--- /dev/null
+++ b/src/function/detail/apply.h
@@ -0,0 +1,86 @@
+#ifndef TYPEASVALUE_SRC_FUNCTION_DETAIL_APPLY_H_
+#define TYPEASVALUE_SRC_FUNCTION_DETAIL_APPLY_H_
+
+#include <type_traits>
+
+#include "list/list.h"
+#include "list/operation/nth.h"
+#include "list/operation/higher/query.h"
+
+namespace tav {
+namespace detail {
+
+struct placeholder_tag { };
+
+template <typename Type>
+using is_placeholder = tav::Boolean<
+ std::is_base_of<placeholder_tag, Type>::value
+>;
+
+template <int Index>
+struct placeholder : placeholder_tag { };
+
+template <
+ typename Partials,
+ typename Argument
+>
+struct resolve_placeholder {
+ typedef Argument type;
+};
+
+template <
+ typename Partials,
+ int Index
+>
+struct resolve_placeholder<Partials, placeholder<Index>> {
+ typedef typename Nth<Size<Index>, Partials>::type type;
+};
+
+template <typename... Arguments>
+using count_placeholders = Count<
+ is_placeholder,
+ typename List<Arguments...>::type
+>;
+
+template <
+ template<typename...> class Function,
+ typename... Arguments
+>
+struct apply_variadic {
+ template <typename... Partials>
+ using type = Function<
+ typename resolve_placeholder<
+ typename tav::List<Partials...>::type,
+ Arguments
+ >::type...
+ >;
+};
+
+template <
+ template<typename...> class Function,
+ typename... Arguments
+>
+struct apply_single : apply_variadic<Function, Arguments...> {
+ template <typename Partial0>
+ using type = typename apply_variadic<
+ Function,
+ Arguments...
+ >::template type<Partial0>;
+};
+
+template <
+ template<typename...> class Function,
+ typename... Arguments
+>
+struct apply_pair : apply_variadic<Function, Arguments...> {
+ template <typename Partial0, typename Partial1>
+ using type = typename apply_variadic<
+ Function,
+ Arguments...
+ >::template type<Partial0, Partial1>;
+};
+
+}
+}
+
+#endif // TYPEASVALUE_SRC_FUNCTION_DETAIL_APPLY_H_