This is not something that can be done portably with C++. You can however change things a little and having your functions accepting a single parameter that is a map containing all the relevant parameters:
typedef std::map<std::string, Anything> Parms;
Anything function1(const Parms& parms)
{
double x = parms("x");
std::string title = parms("title");
...
}
void init_module()
{
register_function("function1", function1,
"void return, double x, string title");
}
In the above example Anything
is a class that can contain any of the types you want to support as parameters or return values. I am used to code it myself but probably boost::any
is ok for that.
Every published function accepts only a dictionary of parameters and the function publishes also the return type and parameters. This information is stored in a map for dispatching and parameter checking so that you don't need to code checking in all functions and also allows publishing directory services.
You could also use instances of classes that implements a "call" method instead of functions for the published services (this is what I'm used to do).
Unfortunately C++ design is not very compatible with this use case and a lot of coding is required. There is no such a thing like "call the function with this name passing these parameters" where the function name and parameters are provided at runtime.
Note that this use is on the other hand not so uncommon and therefore you can find a lot of libraries that try to add this dinamicity to C++... how they fit to your exact problem, what dependencies they have and how complex they are is something that must be considered.