howto make a function get types form compile-time-parameters AND from arguments ?

John Colvin john.loughran.colvin at gmail.com
Thu Oct 31 03:26:15 PDT 2013


On Thursday, 31 October 2013 at 10:18:25 UTC, Uplink_Coder wrote:
>
> Maybe I shuold be more specific :
> for now It's:
> T[] arr = makeArray!(T,U)([some,instances,of,U]);
>
> but I would like it to be:
>
> auto arr = makeArray!(T)([some,instances,of,U]);

void foo(T,U)(U arg){}

int a;
foo!(double)(a); //U is inferred as int


void bar(T,U)(U[] arg){}

long[] b;
foo!(double)(b); //U is in inferred as long


However, be aware that you can't pass mutable or const data as an 
immutable argument. Perhaps the signature that would work better 
for you would be

T[] makeArray(T,U)(const U[] paramArray)


More information about the Digitalmars-d-learn mailing list