Help needed to learn templates

Vinod K Chandran kcvinu82 at gmail.com
Sat Mar 19 13:38:42 UTC 2022


On Saturday, 19 March 2022 at 11:47:53 UTC, Stanislav Blinov 
wrote:
>
> No.
>
First of all Thanks for the reply. The answer "No" is a wonder to 
me. Because, from my point of view, `U` is coming from nowhere. 
My understanding is, we can use any parameter of a template 
inside the template. So in this case `U` is not in the parameter 
list. It is suddenly appearing in that `static if`.


> The test is not `T t == U[]`. It is `is(T t == U[], U)`.
>
Okay, I understand.

> Actually, the lower case `t` is not needed there, you can 
> simply write `is(T == U[], U)`.
>
So the `T` is not the type. It's the parameter. Right ? So a 
template doesn't need a type. Only the parameter, right ? (I 
think I am too dumb to ask this. Please forgive me.)

> Yes, and `U` then becomes `int[][]`. Which is why the template 
> recurses down and instantiates itself with `U`, until `T` fails 
> the test.
>
In order to understand this, I need to understand from where the 
`U` comes.




More information about the Digitalmars-d-learn mailing list