Template for going from Array --> list of args

Bill Baxter dnewsgroup at billbaxter.com
Tue Jan 30 12:55:38 PST 2007


Kirk McDonald wrote:
> Bill Baxter wrote:
> 
> Something like this should work (though I haven't tested it):

Works indeed!  Thanks.

> 
> import std.traits;
> 
> void callwith(alias fn, T)(T[] array) {
>     ParameterTypeTuple!(typeof(&fn)) t;

Whoa, didn't realize you could make a variable out of a type tuple.  Or 
if I did know it once, I completely forgot it.

>     foreach (i, e; t) {
>         t[i] = array[i];
>     }

I guess this squashes any hope of the thing getting inlined... :-(

>     fn(t);
> }
> 
> void foo(int a, int b) { }
> 
> void main() {
>     int[5] a = [0,1,2,3,4];
>     callwith!(fn, int)(a);
> }
> 

--bb


More information about the Digitalmars-d-learn mailing list