[C++] General container of "callable entities"?
boost::bind, std::mem_fn etc generalize applying function pointers/functors/member function pointers to STL algorithms.
Is something similar available (in STL or boost for example) for storing polymorphic mixes of function pointers, functors and member functions?
The idea is to do things such as storing polymorphic collections of different "callable entities" in the same STL container, like an std::map mapping from a string to a "callable entity". A possible implementation might be to create an abstract base class defining a function call operator with a signature S and provide subclasses implementing the operator using either of a function pointer, by value-held functor, a member function+an object to invoke it with, etc.
Is anything like this available?
boost::bind with boost::function. You mentioned it, but apparently you aren't fully aware of its capabilities. If you store std::vector of boost::function, you can use boost::bind to bind any free or member function, and store it in the vector.
C++ standard has adapted the functionality of Boost::function. Both g++ and VC++ have implemented it.
However, bind is something I think you'll still need Boost for.
However, bind is something I think you'll still need Boost for.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement