How to call function with variable arguments at runtime?

bauss jj_1337 at live.dk
Tue Oct 10 08:21:56 UTC 2017


On Tuesday, 10 October 2017 at 02:58:45 UTC, Mr. Jonse wrote:
> I need to store a hetrogeneous array of delegates. How can I do 
> this but still call the function with the appropriate number of 
> parameters at run time?
>
> I have the parameters as Variant[] params and a 
> function/delegate pointer(void* for now).
>
> Normally I'd push the parameters on the stack and use a call, 
> but I'm sure D has some ability to do this, like apply(foo, 
> args) would be the same as foo(args[0], ..., args[1]).
>
> I'm not concerned about type correctness, it should always be 
> consistent between what I call and what is stored.
>
> Thanks.

Not entirely sure what you're wanting to do, but sounds a lot 
like variadic parameters.


https://dlang.org/spec/function.html#variadic mixed with some 
compile-time terminology.


More information about the Digitalmars-d-learn mailing list