I was doing some metaprogramming where I wanted to make a slice of a type:

alias Tbasic = int;
pragma(msg, Tbasic);
alias Tbasica = Tbasic[];
pragma(msg, Tbasica);

//prints int, int[]

And things worked fine until I attempted the same thing on what happened to be a tuple of 1 element:


alias Ts = AliasSeq!int;
pragma(msg, Ts);
alias Tsa = Ts[];
pragma(msg, Tsa);
//prints (int), (int)

which confused me until I realized that the [] was slicing the tuple. Note, you can add as many [] as you want since it's basically a no-op.

pragma(msg, Ts[0][]); //prints int[]

Is there any use for this behavior? It seems like it might be worth warning like "slicing a tuple is a no-op"

Anyway, figured I'd post here for posterity since I was confused by it for a while.


Reply via email to