I'm trying to figure out how to create a C++11 template function which would convert function calls between two conventions : the first one is using Variant (note : a variant is a polymorphic type which is the base for the subclasses IntVariable, DoubleVariant, etc), the second one is the C function call.

We know every piece of information at the compile time : the argument count is the number of parameters, and the arguments/return type depends of the 'cfunc' variable type.

@Nison: I wouldn't really call it "black magic", as the trick itself is rather easy once understood. You basically generate a variadic arguments pack of indices. This generation is done through recursion by prepending progressively smaller indices, until 0 is reached.
–
XeoOct 7 '12 at 2:16