
On Thu, 15 Sep 2005 10:47:41 -0300, Simon Carter
I would like to do the same thing - boost::bind can be used to bind an instance of an object, a member function pointer _and_ any parameters required by that function.
This leads to a really useful implementation of the command pattern - you can build a list of these functors which constitute a composite command, and to serialise the whole lot - or part - would be invaluable in all sorts of situations including tracking how much of the composite command had actually been implemented.
Maybe I should generalise and boostify my implementation. Any interest?
Yes. Could you explain it's principles? I've been trying to solve the same problem for some time now. The first difficulty is the serialization of a boost::function like class. A possible implementation for such a class is defining an abstract base class and creating by template means the apropiate subclass in the constructor. Boost.Serialization requires registration of all these classes but there's an unbounded number of possible implementations. I've 'solved' this by relying in typeinfo::name which is unportable but works. See a recent thread started by me on this topic. The second problem is serialization of the argument functors themselves. For a user written one, this is easy. For boost::bind it's hard. If the functor adapted by bind is a pointer to function, we are out of luck, as boost::serialization chokes on these. It would be conceivable to have facilities to register pointer to functions, but there aren't any now. boost::bind returns objects of unspecified type, so giving them serialization is hacky at best. They aren't DefaultConstructable. If they were, the visitor facility would be of use (some const_cast would be needed here). Note that boost::function uses a different strategy, in which only pointers to functions are stored inside, not pointers to objects, in order to avoid code bloat. This is where I am now. I'm very interested to learn about your implementation. Regards, Bruno