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 mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
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)>
...
It looks like right area, but i can't see how would I apply these.
function_type expects mpl sequense.
function_type expects mpl sequense.
Maybe what you need is a combinatioin of FunctionTypes and TypeTraits
//example with type_traits/function_traits
#include<boost/static_assert.hpp>
#include<boost/type_traits/function_traits.hpp>
struct newf : boost::function_traits<int(int,int)>{
BOOST_STATIC_ASSERT(arity==2);
result_type operator()(arg1_type a, arg2_type b){ //or
result_type operator()(first_argument_type a, second_argument_type b){
return a+b;
}
};