I want to store function pointers with different signature in a std::map as a value. Is this possible in C++
2 Answers
It is possible by using something like Boost.Any or Boost.Variant. Keep in mind, however, that you will have to remember somehow what the signature of the function stored (hidden) inside the boost::any object is, so you can retrieve it.
Comments
You do not even need to use boost. You can simply use a functor( overload () operator) as a base class and inherit from it for every different function you need.
1 Comment
Simon Meister
Sure, but it would be easy to change the functions from using a return type to reference parameters. Of course i agree to using boost, if you have no chance to change the functions returntype (3rd party/external functions)