[C++] General container of "callable entities"?

Started by
5 comments, last by sb01234 15 years, 3 months ago
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?
http://www.better-than-real.net/sb/
Advertisement
boost::function
Sounds like you're after boost::function?
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.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

And then there's boost::signal.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

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.
Thanks, boost::function is what I was looking for.
http://www.better-than-real.net/sb/

This topic is closed to new replies.

Advertisement