Template class with variadic arguments
-
I have some troubles with generating a C++ template class. Goal is to add a function call with its arguments to a list for execution in a different task. The environment is a resource limited embedded system with a small task scheduler. I did some experiments, followed the An Idiot's Guide to C++ Templates but I’m not able to get this working:
template
class InstructionFunctionCall : public Instruction
{
private:
// remember what to call... (with arguments)public:
/// Execute instruction, called from a difrent task.
virtual void execute (class Env *env)
{
// call the function with params.
}SeBusInstructionFunctionCall(\_CallFunction Function, \_Args... Args) { // store the call information. }
};
Could anybody give me a clue how I could template the storage of the variable arguments and use them in a function call? So I like to create an object with probably look someway like this:
InstructionFunctionCall *function = new InstructionFunctionCall(SomeFunction, arg1, arg2);
And later on where the call need to be executed:
function->execute(); // executes: SomeFunction(arg1, arg2)
Meanwhile I found this: Elegant Function Call Wrappers | Dr Dobb's article. It seems to be able do almost what I want, but it does not support a variable number of args.