Now that's a DIP that could use some love

claptrap clap at trap.com
Fri Sep 18 09:32:29 UTC 2020


On Thursday, 17 September 2020 at 23:10:23 UTC, jmh530 wrote:
>>
> template ArrayType(T)
> {
>     import std.traits: isDynamicArray;
>     static if (isDynamicArray!T) {
>         alias ArrayType = T;
>     } else {
>         static assert(0, "T is not a valid ArrayType");
>     }
> }
>
> void foo(T)(ArrayType!T x) {
>  	
> }
>
> void main()
> {
>     int[] x;
>     foo(x); //does not currently compile
>     int y;
>     foo(y); //does not currently compile, shouldn't compile
> }

Pretty cool that. It occurs to me that it may not be even 
necessary to declare the template parameter up front, it could 
just be...

void foo(ArrayType!T x)

That could be lowered / rewritten by the compiler back to..

void foo(T)(ArrayType!T x)




More information about the Digitalmars-d mailing list