Call a function passed as template parameter.

moechofe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Sep 3 04:31:20 PDT 2015


Hi,

I would like to create a template that take a function as 
template parameter, create an arguments list for it, fill it with 
some data and call the function.

void foo(uint a, string b)
{
   // ...
}

void bar(long a, long b, string c)
{
   // ...
}

call(alias F)(JSONValue j)
{
   // create arguments list
   // assign arguments with the value from j
   // call the function
}

void main()
{
   call!foo(parseJSON("[123, \"nice\"]"));
   call!bar(parseJson("[1,2,3]"));
}

I found interesting stuff like ParameterTypeTuple! and Tuple! but 
I'm not be able to make it work together.

How can I do that?


More information about the Digitalmars-d-learn mailing list