Generating a functor from a member function pointer type

I am trying to simplify (through make_fn()) the creation of functors that pre-process parameters (through wrap()) for arity n member functions.
The generation of functors basically works, but so far only by explicitly specifying parameter types for a member function.
Now I would like to generate the correct functor from the type of the member function that it controls:

struct X {};

template<class C, typename T1, bool (C::*F)(T1)>
inline // there are more for T1..TN
bool wrap(C* c, X x) 
{
    return (c->*F)(process<T1>(x));
}

template<class C, typename T1, bool (C::*F)(T1)> 
inline // there are more for T1..TN
boost::function<bool (C*, X)> make_fn(F f) // <- problem here, F is not a type
{
    return boost::bind(&wrap<C, T1, F>, _1, _2);
}

With this, however, vC ++ and g ++ are not seen Fas a type for a parameter make_fn(). I have to skip something obvious here and feel a little blind.

The idea was that it should work as follows:

struct A 
{
    bool f1(bool) { return true; }
};

void test()
{
    A a;
    X x;
    make_fn(&A::f1)(&a, x);
}

Any ideas on how to make this work?

:
, :

bool invoke(C* c, const char* const functionName, int argCount, X* args);

X - , (int, std::string,...).
, - .
, , throw. , .
, -.

+5
1

, , , , , , (. ).

, . :

#include <boost/bind.hpp>
#include <boost/function.hpp>

struct X {};

template <class T>
bool process(X) { return true; }


template <class C, class T1, class Func>
struct wrap1
{
    typedef bool result_type;
    Func f;

    wrap1(Func f): f(f) {}

    bool operator()(C* c, X x)
    {
        return (c->*f)(process<T1>(x));
    }
};

template<class C, typename T1>
inline // there are more for T1..TN
boost::function<bool (C*, X)> make_fn(bool (C::*f)(T1))
{
    return boost::bind(wrap1<C, T1, bool (C::*)(T1)>(f), _1, _2);
}


struct A
{
    bool f1(bool) { return true; }
};

void test()
{
    A a;
    X x;
    make_fn(&A::f1)(&a, x);
}

, . , .:)

+3

All Articles