8 #ifndef BLACKCAT_BIND_H_ 9 #define BLACKCAT_BIND_H_ 13 #include "../common.h" 31 template<
class Function,
class... Args>
32 struct Bind: tuple<Args...>
36 Bind(Function func, Args... AdditionalArgs):
37 tuple<Args...>(AdditionalArgs...), func(func) {}
39 static constexpr
int num_args =
sizeof...(Args);
43 template<
class... TupleArgs>
44 auto call(true_type, TupleArgs&&... params)
const 45 -> decltype(func(forward<TupleArgs>(params)...))
47 return func(forward<TupleArgs>(params)...);
50 template<
class... TupleArgs>
51 auto call(true_type, TupleArgs&&... params)
52 -> decltype(func(forward<TupleArgs>(params)...))
54 return func(forward<TupleArgs>(params)...);
57 template<
class... TupleArgs,
int ArgCount=
sizeof...(TupleArgs)>
58 auto call(false_type, TupleArgs&&... params)
const 62 forward<TupleArgs>(params)...,
63 std::get<ArgCount>(*
this)))
68 forward<TupleArgs>(params)...,
69 std::get<ArgCount>(*
this));
72 template<
class... TupleArgs,
int ArgCount=
sizeof...(TupleArgs)>
73 auto call(false_type, TupleArgs&&... params)
77 forward<TupleArgs>(params)...,
78 std::get<ArgCount>(*
this)))
83 forward<TupleArgs>(params)...,
84 std::get<ArgCount>(*
this));
89 template<
int ADL=0,
class=std::enable_if_t<ADL==0>>
96 template<
int ADL=0,
class=std::enable_if_t<ADL==0>>
97 auto operator () ()
const 104 template<
class Function,
class... Args>
105 Bind<Function, Args&&...>
bind(Function
function, Args&&... args) {
106 return {
function, std::forward<Args>(args)... };
Bind< Function, Args &&... > bind(Function function, Args &&... args)
Definition: bind.h:105
Bind(Function func, Args... AdditionalArgs)
Definition: bind.h:36
Function func
Definition: bind.h:34
conditional_t< Bool, true_type, false_type > truth_type
Definition: type_traits.h:49
Similar to std::bind but the evaluation of the function in respect to its bound arguments are deduced...
Definition: bind.h:32
The Evaluator determines if an expression needs to be greedily optimized.
Definition: algorithms.h:22