I am trying to write a general wrapper (for some script interpreter) for a function / class method that converts all call parameters from a string to an arbitrary type T. I will try to highlight the topic in points:
- Script allows you to display a user function
- When the interpreter tries to process the user-defined function, the callback procedure is executed
- The callback is intended to receive an array of objects that describe (one at a time) the values of the arguments
- I already have (template) routines that convert a string to an arbitrary (basic) type T
- I would like to wrap a user procedure (provided externally as a varadic std :: function <> type) so that the conversion from subsequent lines from the callback array to the corresponding argument is done automatically
Example:
The prototype for the callback procedure is as follows:
int CallbackFn(Interp *interp, int argc, const char **argv)
I got a (sample) custom function:
int UserRoutine(const std::string &in_str, int x);
so std :: function will look like this:
std::function<int(const std::string&, int)>
The general conversion procedure has the syntax:
template <typename T>
T conv(const char *str);
I have specializations that convert:
- "const char *" to "std :: string"
- "const char *" to "int"
so that ideally the conversion would look like this:
std::string p0 = conv<std::string>(argv[0]);
int p1 = conv<int>(argv[1]);
, std:: function <... > , - . const T &, "" T.
, ?