1

I have an unordered_map of functions that should be called on an object when an XML file is parsed.
I have found that boost::function has a base class named boost::function_base, however as expected I cannot invoke it because I don't have the signuture of the function.
Since all of those functions are setter functions, I can guarantee that they return void and have only one parameter of an unknown type.
Is there any better way to resolve the type other then an if-else-if branch which I am trying to avoid?

kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005
the_drow
  • 18,571
  • 25
  • 126
  • 193

2 Answers2

2

Use a boost::variant is the best way to go. How could you possibly invoke a function with an unknown parameter type, anyway?

Puppy
  • 144,682
  • 38
  • 256
  • 465
0

boost::function is designed for compile time polymorphism only. Why don't you just use a regular function pointer? I.e.

typedef void (*function_type)(void *);
Billy ONeal
  • 104,103
  • 58
  • 317
  • 552