Help needed to learn templates

Vinod K Chandran kcvinu82 at
Sun Mar 20 08:27:44 UTC 2022

On Saturday, 19 March 2022 at 22:31:19 UTC, Stanislav Blinov 
> It is appearing not in the `static if`, but in the `is` 
> expression, which I described further in the rest of my first 
> reply. Sorry if that wasn't clear.
No, it was my mistake, I missed it.

> The other template syntax - `template foo(alias T)` can take as 
> `T` any symbol, not just a type.
I understand this.

> It comes from you, the programmer. Like I said before, `is(T == 
> U[], U)` means "is T an array of some type, the type which I 
> (the programmer) would like to refer to as U?". That's all 
> there is to it (well, not quite, but it should suffice for 
> starters). You're simply introducing an identifier. So, when 
> `T` is an `int[][][]`, naturally, `U` becomes an alias to 
> `int[][]` (look at the converse - when `U` is `int[][]`, `U[]` 
> is naturally an `int[][][]`).
Okay, got it.

> You can think of that test as this:
> ```d
> import std.traits : isDynamicArray;
> // ...
> static if (isDynamicArray!T)
> {
>     alias U = typeof(T.init[0]);
>     // ...
> }
> ```
Yes, in this case everything is simple and clear.

> ...which would roughly be the same thing - you test if `T` is a 
> dynamic array of some type, and then make an alias for that 
> array's element type. It's just that the `is` expression allows 
> you to create such alias in situ.
Okay. Got the point. Thanks. Now, I understand that why Ali 
suggest me to learn **`is()`** expression.

More information about the Digitalmars-d-learn mailing list