From 8b6de4c8c89d31c5d0e16548767ef21f242aadd1 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sun, 25 Jan 2015 20:35:38 +0100 Subject: Implemented partial function application prototype * function `Apply` enables partial supply of the template parameters of a given _function_ ** unsupplied parameters may be marked by _placeholders_, i.e. approach is similar to `std::bind` ** returns a template type taking the remaining, unsupplied parameters of the partially applied _function_ * this is a prototype in the sense, that neither full application using `Apply` or partial application of higher order functions is currently supported ** e.g. a `single_type` alias type declaration is required as the variadic template `template` doesn't directly map to `template` * appropriate test cases document current feature set * the goal is to enable a concise defintion of _lambda-like_ expressions for easy specialization of e.g. functors provided to higher order functions --- src/function/apply.h | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/function/apply.h (limited to 'src') diff --git a/src/function/apply.h b/src/function/apply.h new file mode 100644 index 0000000..d353169 --- /dev/null +++ b/src/function/apply.h @@ -0,0 +1,64 @@ +#ifndef TYPEASVALUE_SRC_FUNCTION_APPLY_H_ +#define TYPEASVALUE_SRC_FUNCTION_APPLY_H_ + +#include + +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; +typedef detail::placeholder<3> _3; + +template < + template class Function, + typename... Arguments +> +struct Apply { + typedef typename tav::List::type argument_list; + + template + using type = Function< + typename detail::resolve_placeholder< + typename tav::List::type, + Arguments + >::type... + >; + + template + using single_type = type; +}; + +} + +#endif // TYPEASVALUE_SRC_FUNCTION_APPLY_H_ -- cgit v1.2.3