If I have a class such as the following:
import std.traits;
class Test(T) if(isCallable!T)
{
alias ParameterTypeTuple!T Parameters;
alias ReturnType!T delegate(Parameters) DelegateType;
DelegateType m_delegate;
void Foo(void ** arguments)
{
// I want to convert the void* array to
// the respective type of each argument
m_delegate(arguments);
}
}
How can I convert a C
array of void pointers to their respective type (where their type is defined in Parameters
and the length ofarguments
equals the length of Parameters
) and then call the function?
I tried to do this using a tuple like the following:
void Foo(void ** arguments)
{
Tuple!(Parameters) tuple;
foreach(index; 0 .. Parameters.length)
{
// Copy each value to the tuple
tuple[index] = *(cast(Parameters[index]*) arguments[index]);
}
// Call the function using the tuple (since it expands to an argument list)
m_delegate(tuple);
}
But this does not compile because the compiler complains about "variable index
cannot be read at compile time". Any ideas?
Do something along these lines:
ParameterTypeTuple!T args;
foreach(i, arg; args) {
args[i] = cast(typeof(arg)) arguments[i];
}
and you should be started