1 #if !defined( INCLUDED_FUNCTIONAL_H )
2 #define INCLUDED_FUNCTIONAL_H
10 struct rank : rank<N - 1> {
25 using func_member = wrapper<typename F::func>;
28 static wrapper<func_member<F>> test(rank<2>) { return {}; }
32 using type = typename func_lambda<decltype(&F::operator())>::type;
35 template<class R, class... Ts>
36 struct func_lambda<R(*)(Ts...)> {
37 using type = R(Ts...);
40 template<class Object, class R, class... Ts>
41 struct func_lambda<R(Object::*)(Ts...) const> {
42 using type = R(Ts...);
45 template<class Object, class R, class... Ts>
46 struct func_lambda<R(Object::*)(Ts...)> {
47 using type = R(Ts...);
50 template<class F, class = func_lambda<F>>
51 static wrapper<func_lambda<F>> test(rank<1>) { return {}; }
57 template<class R, class... Ts>
59 using result_type = R;
62 using get = typename std::tuple_element<N, std::tuple<Ts...>>::type;
66 template<class Caller>
67 using get_func = typename decltype(detail::get_func::test<Caller>(detail::rank<2>{}))::type::type;
69 template<class Caller>
70 using get_result_type = typename detail::Fn<get_func<Caller>>::result_type;
72 template<class Caller, int N>
73 using get_argument = typename detail::Fn<get_func<Caller>>::template get<N>;
80 template<class R, class... Ts>
81 class FunctionN<R(Ts...)> {
83 template<R(*f)(Ts...)>
86 using func = R(Ts...);
88 static R call(Ts... args) {
96 template<class F, F *func>
97 using Function = typename detail::FunctionN<F>::template instance<func>;
100 template<class Object, class F>
101 struct MemberFunction;
103 template<class Object, class R, class... Ts>
104 struct MemberFunction<Object, R(Ts...)> {
105 using type = R(Object::*)(Ts...);
106 using type_const = R(Object::*)(Ts...) const;
111 template<class Object, class F>
114 template<class Object, class R, class... Ts>
115 class MemberN<Object, R(Ts...)> {
117 template<R(Object::*f)(Ts...)>
120 using func = R(Object &, Ts...);
122 static R call(Object &object, Ts... args) {
123 return (object.*f)(args...);
129 template<class Object, class F>
130 using MemberFunction = typename detail::MemberFunction<Object, F>::type;
132 template<class Object, class F, MemberFunction<Object, F> func>
133 using Member = typename detail::MemberN<Object, F>::template instance<func>;
136 template<class Object, class F>
139 template<class Object, class R, class... Ts>
140 class ConstMemberN<Object, R(Ts...)> {
142 template<R(Object::*f)(Ts...) const>
145 using func = R(const Object &, Ts...);
147 static R call(const Object &object, Ts... args) {
148 return (object.*f)(args...);
154 template<class Object, class F>
155 using ConstMemberFunction = typename detail::MemberFunction<Object, F>::type_const;
157 template<class Object, class F, ConstMemberFunction<Object, F> func>
158 using ConstMember = typename detail::ConstMemberN<Object, F>::template instance<func>;
167 template<int N, int... S>
168 struct gens : gens<N - 1, N - 1, S...> {
172 struct gens<0, S...> {
173 using type = seq<S...>;
177 using seq_new = typename gens<N>::type;
179 template<class Functor, class F>
180 class FunctorNInvoke;
182 template<class Functor, class R, class... Ts>
183 class FunctorNInvoke<Functor, R(Ts...)> {
184 std::tuple<Ts...> args;
190 struct caller<seq<I...>> {
191 static inline R call(FunctorNInvoke<Functor, R(Ts...)> *self, Functor functor) {
193 return functor(std::get<I>(self->args)...);
198 FunctorNInvoke(Ts... args) : args(args...) {
201 inline R operator()(Functor functor) {
202 return caller<seq_new<sizeof...(Ts)>>::call(this, functor);
207 template<class Functor>
208 using FunctorInvoke = detail::FunctorNInvoke<Functor, get_func<Functor>>;