Boost logo

Boost Users :

Subject: [Boost-users] [function/bind] function object type introspection
From: Gennadiy Rozental (rogeeff_at_[hidden])
Date: 2009-10-01 05:02:45


Hi,

I've got couple questions. Might be someone can point me in right direction.

Let's say I've got this class ConcreteFunctor which should handle all
kinds of functions. I want to store the function as boost::function
object, thus the class has template parameter - FunctionType:

template<typename FuncType>
ConcreteFunctor : public AbstractFunctor {
     ConcreteFunctor( FuncType f ) ... {}

     virtual invoke( std::vector<Object*> const& args )
     {
        // here I can use FuncType::arity and FuncType's argument types
        // to properly convert arguments to desired types and invoke m_f
     }

     FuncType m_f;
}

Now I need to implement object maker

template<typename F>
boost::shared_ptr<AnstractFunctor>
make_functor( F f )
{
   typedef boost::function<???> TypeName;
   return boost::shared_ptr<AbstrctFunctor>(
      new ConcreteFunctor<FuncType>( f ) );
}

I was able to work fine with free functions by just removing pointer
from F. Now to the questions:

1. How do I deduce boost::function type from pointer to member functions:

Essentially if F is R (A::*)(T1,T2) I need to get
boost::function<T (A*,T1,T2)>

2. This is more difficult: if f is bound object, how to I intrspect it's
type:

Essentially in use case like this:

int foo( std::string, int ) {...}

make_functor( boost::bind( &foo, "abc" ) )

I want to get FuncType as boost::function<int (int)>

Regards,

Gennadiy


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net