Commit 9366bd80 authored by Dominik Charousset's avatar Dominik Charousset

simplified invoke process of match_expr

this patch reduces the complexity and code size for the invoke
process of match_expr by using a recursive `unroll_expr` function
rather than using nested template metaprogramming facilities;
futhermore, this patch reshapes `apply_args` to take a tuple with
an indices list, aiming to replace the clumsy `apply_tuple` family
in the long run
parent 373ccf36
......@@ -34,6 +34,7 @@
#include "cppa/option.hpp"
#include "cppa/guard_expr.hpp"
#include "cppa/util/int_list.hpp"
#include "cppa/util/rm_option.hpp"
#include "cppa/util/type_list.hpp"
#include "cppa/util/apply_args.hpp"
......@@ -115,7 +116,8 @@ class projection {
typename tdata_from_type_list<collected_args>::type pargs;
if (collect(pargs, m_funs, std::forward<Args>(args)...)) {
projection_helper<PartialFun> helper{fun};
return util::unchecked_apply_tuple<bool>(helper, pargs);
auto indices = util::get_indices(pargs);
return util::apply_args(helper, pargs, indices);
}
return false;
}
......@@ -140,7 +142,8 @@ class projection {
typename tdata_from_type_list<collected_args>::type pargs;
if (collect(pargs, m_funs, std::forward<Args>(args)...)) {
result_fetching_projection_helper<PartialFun> helper{fun, result};
return util::unchecked_apply_tuple<bool>(helper, pargs);
auto indices = util::get_indices(pargs);
return util::apply_args(helper, pargs, indices);
}
return false;
}
......
This diff is collapsed.
......@@ -83,8 +83,7 @@ class tpartial_function {
}
result_type operator()(Args... args) const {
return util::apply_args<Result, util::tl_size<ctrait_args>::value, sizeof...(Args)>
::_(m_expr, args...);
return util::partially_apply<result_type,util::tl_size<ctrait_args>::value>(m_expr, args...);
}
private:
......
......@@ -33,25 +33,52 @@
#include <cstddef>
#include "cppa/get.hpp"
#include "cppa/util/int_list.hpp"
namespace cppa { namespace util {
template<typename F, class Tuple, long... Is>
auto apply_args(F& f, Tuple& tup, util::int_list<Is...>)
-> decltype(f(get_cv_aware<Is>(tup)...)) {
return f(get_cv_aware<Is>(tup)...);
}
template<typename F, class Tuple, long... Is, typename... Args>
auto apply_args_prefixed(F& f, Tuple& tup, util::int_list<Is...>, Args&&... args)
-> decltype(f(std::forward<Args>(args)..., get_cv_aware<Is>(tup)...)) {
return f(std::forward<Args>(args)..., get_cv_aware<Is>(tup)...);
}
template<typename F, class Tuple, long... Is, typename... Args>
auto apply_args_suffxied(F& f, Tuple& tup, util::int_list<Is...>, Args&&... args)
-> decltype(f(get_cv_aware<Is>(tup)..., std::forward<Args>(args)...)) {
return f(get_cv_aware<Is>(tup)..., std::forward<Args>(args)...);
}
template<typename Result, size_t NumFunctorArgs, size_t NumArgs>
struct apply_args {
struct partially_apply_helper {
template<class Fun, typename Arg0, typename... Args>
static Result _(const Fun& fun, Arg0&&, Args&&... args) {
return apply_args<Result, NumFunctorArgs, sizeof...(Args)>
return partially_apply_helper<Result, NumFunctorArgs, sizeof...(Args)>
::_(fun, std::forward<Args>(args)...);
}
};
template<typename Result, size_t X>
struct apply_args<Result, X, X> {
struct partially_apply_helper<Result, X, X> {
template<class Fun, typename... Args>
static Result _(const Fun& fun, Args&&... args) {
return fun(std::forward<Args>(args)...);
}
};
template<typename Result, size_t Num, typename F, typename... Args>
Result partially_apply(F& f, Args&&... args) {
return partially_apply_helper<Result,Num,sizeof...(Args)>
::_(f, std::forward<Args>(args)...);
}
} } // namespace cppa::util
#endif // CPPA_APPLY_ARGS_HPP
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment