Is there something like "apply"?

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Apr 28 10:52:57 PDT 2015


Easiest is to just do it by hand:

foo(args[0], args[1]);

This can also be automated with a bit of code in a lot of cases:

import std.traits;

ParameterTypeTuple!foo params;
foreach(index, ref param; params) {
     params[index] = args[index];
}

foo(params);


Move that into a helper function and you can call it apply.

You could also make that assignment in the loop to type 
conversion if you wanted, my jsvar.d does this to provide 
javascript-style functions with an apply method.


More information about the Digitalmars-d-learn mailing list