
On Sun, Sep 19, 2010 at 12:52 PM, Anonymous user
Hello,
Thanks for the quick response !
It is a good solution, but hhat I try to do is the following:
template
struct my_class {
boost::function
*m_f; template<typename Functor> my_class(Object &obj,Functor &f,Type & newValue) { m_f= boost::bind(f,&obj); }
... void serialize(Archive &ar, const unsigned int version) { ar & m_f; //does not compile }
};
Instantiation:
MyObject myObject("old value"); my_class < MyObject,std::string> m(myObject,&MyObject::setName,e,"new value");
Thus the idea is to avoid changing the design (no inheritance to create functor) and just use boost::function to create dynamically functors. My problem is to rebuild dynamically the boost::function in the serialization step. I really needs to avoid using inheritance on my classes just to creates functors, thus I really need to keep the current design and just build dynamically functors through boost::bind.
One possible idea was to register a pair of types -> object which contains the function and the functor. Example:
template
struct my_class {
typedef boost::mpl::pair
typedef boost::mpl::map< key,value > > Functions;
template<typename Functor> my_class(Object &obj,Functor &f,Type & newValue) { m_f= boost::bind(f,&obj); typedef boost::mpl::insert< Functions,Functor > > t; }
...
template <class Archive> void serialize( Archive & ar, const unsigned int version ) { typedef boost::mpl::at<key>()::type t; ar & t; //not possible -> does not instantiate the real functor address ! }
};
The problem is the above solution is that we don't store the functor address but only it's signature.
If you have an idea to make this example working or another idea to store functors which have been created dynamicaly, don't hesitate.
Thanks again for your help !
As he said, you cannot do it using that method. Do *not* use boost/std::function or bind anywhere! You have to use a virtual base with specialized children if you are going to be 'bind'ing things.