From ad27a79a2e6bc380e68ec77ae961917a9fb402d3 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Thu, 12 Feb 2015 10:16:54 +0100 Subject: Revamped partial function application * moved internals into separate header i.e. the `detail` namespace relating to `Apply` * implemented automatic alias selection by implementing aliae of the basic variadic `type` template alias in different base classes ** variadic partial application is implemented in `detail::apply_variadic` *** `detail::apply_single` and `detail::apply_pair` define aliae to `detail::apply_variadic`'s `type` template alias *** both restricted aliae derive from `detail::apply_variadic` ** `Apply` derives from any of the aliae defining base classes depending on the count of placeholders as determined by `detail::count_placeholders` *** `Apply` is guaranteed to always be derived from `detail::apply_variadic` one way or the other * changed functions, test cases and examples depending on `Apply` accordingly ** `Length` had to be reimplemented without `Apply` as it doesn't allow usage of aliae expecting a different count of arguments anymore *** this is a advantage in the sense that core functionality of _TypeAsValue_ now doesn't depend on this complex partial application implementation anymore *** such functionality may be reimplemented separately from `Apply` * removed unnecessary `tav` namespace prefixes --- src/function/apply.h | 62 ++++++++++------------------------------------------ 1 file changed, 11 insertions(+), 51 deletions(-) (limited to 'src/function/apply.h') diff --git a/src/function/apply.h b/src/function/apply.h index 8e780e0..21364a8 100644 --- a/src/function/apply.h +++ b/src/function/apply.h @@ -1,43 +1,12 @@ #ifndef TYPEASVALUE_SRC_FUNCTION_APPLY_H_ #define TYPEASVALUE_SRC_FUNCTION_APPLY_H_ -#include +#include "conditional/if.h" -#include "list/list.h" -#include "list/operation/nth.h" +#include "detail/apply.h" namespace tav { -namespace detail { - -struct placeholder_tag { }; - -template -using is_placeholder = tav::Boolean< - std::is_base_of::value ->; - -template -struct placeholder : placeholder_tag { }; - -template < - typename Partials, - typename Argument -> -struct resolve_placeholder { - typedef Argument type; -}; - -template < - typename Partials, - int Index -> -struct resolve_placeholder> { - typedef typename Nth, Partials>::type type; -}; - -} - typedef detail::placeholder<0> _0; typedef detail::placeholder<1> _1; typedef detail::placeholder<2> _2; @@ -47,24 +16,15 @@ template < template class Function, typename... Arguments > -struct Apply { - template - using variadic_type = Function< - typename detail::resolve_placeholder< - typename tav::List::type, - Arguments - >::type... - >; - - template - using single_type = variadic_type; - - template - using pair_type = variadic_type; - - template - using triple_type = variadic_type; -}; +struct Apply : If< + (detail::count_placeholders::type::value > 2), + detail::apply_variadic, + typename If< + detail::count_placeholders::type::value == 2, + detail::apply_pair, + detail::apply_single + >::type +>::type { }; } -- cgit v1.2.3