C
Clay_Culver
I have heard that it is possible to use classes + template magic to
make standalone functions (or maybe just a functor which acts like a
function) which can accept variable length arguments without using the
elipse. For example, a funciton could take in 1 known type, then a
variable list of other parameters:
ReturnValueClass rvc = someFunction("Some known type", 1, 0.2,
"string");
ReturnValueClass rvc2 = someFunction("Some known type again", true, 0);
This is without defining someFunction with the various different types
involved. Boost.Python does this with their "call" method which always
takes in a PyObject * as the first parameter, has a template for the
return value, and everything else after the first parameter is
magically accepted. This is example calling it:
int return1 = call<int>(somePyObject1, 'a', 1, true);
double return2 = call<double>(somePyObject2, 0.123, 4.2);
bool return 3 = call<bool>(somePyObject3);
Does anyone know where I can learn how to do this? I have started
digging through the Boost.Python source to learn, but that is a
veritable quagmire of templates, macros, and calls. It looks like it's
done by making the call "function" a class/struct, and the function
paramaters are made legal by templating+a macro expansion in the
template. Beyond that I'm having trouble figure out how to do this (my
use for this is very similar to what boost.python is doing, only with
something other than Python).
I'm not actually looking for someone to explain this complex topic here
on the group (though that would be great). I really just want to know
if anyone can link me to a minimal example/tutorial of how to do this
that I can build on for my own application
Thanks...
make standalone functions (or maybe just a functor which acts like a
function) which can accept variable length arguments without using the
elipse. For example, a funciton could take in 1 known type, then a
variable list of other parameters:
ReturnValueClass rvc = someFunction("Some known type", 1, 0.2,
"string");
ReturnValueClass rvc2 = someFunction("Some known type again", true, 0);
This is without defining someFunction with the various different types
involved. Boost.Python does this with their "call" method which always
takes in a PyObject * as the first parameter, has a template for the
return value, and everything else after the first parameter is
magically accepted. This is example calling it:
int return1 = call<int>(somePyObject1, 'a', 1, true);
double return2 = call<double>(somePyObject2, 0.123, 4.2);
bool return 3 = call<bool>(somePyObject3);
Does anyone know where I can learn how to do this? I have started
digging through the Boost.Python source to learn, but that is a
veritable quagmire of templates, macros, and calls. It looks like it's
done by making the call "function" a class/struct, and the function
paramaters are made legal by templating+a macro expansion in the
template. Beyond that I'm having trouble figure out how to do this (my
use for this is very similar to what boost.python is doing, only with
something other than Python).
I'm not actually looking for someone to explain this complex topic here
on the group (though that would be great). I really just want to know
if anyone can link me to a minimal example/tutorial of how to do this
that I can build on for my own application
Thanks...