Q:

C++11 How to store pointers-to-methods in std::unordered_map?

I want to store in std::unordered_map<object, std::vector<pointer>> pair of object and vector of pointers to methods of that object. object can refer to any class T and pointer must contain pointers to methods from T instance. I must be able to call those methods later. I tried to use boost::any, but I was not able to call methods later. How can I accomplish it?

A:

You can use std::function< void() >.
std::map<object, std::vector<std::function<void()> > functions;

consider to use std::bind if you need to bind some member functions and put them in.
Or if you don't like this you can a use pure virtual interfaces and store it to your vector
IObject{
 virtual void doSomething()=0;
};
std::map<object, std::vector<IObject*> > functions;

then use it to call doSomething.

