AliasSeq can contain template identifier too?

Mike Parker via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Dec 12 06:47:23 PST 2015


On Saturday, 12 December 2015 at 14:15:37 UTC, Shriramana Sharma 
wrote:
> https://github.com/D-Programming-Language/phobos/blob/master/std/meta.d#L790
>
> Looks like an AliasSeq can contain a template identifier too. 
> So should I understand that AliasSeq in general can refer to 
> any identifier and any value? Hitherto I thought it was any 
> *type* and any value...

Templates can take type, expression (value) and alias parameters. 
The latter can be symbols. Variadic templates, those with T... 
parameters, can accept all of those. There are also template this 
parameters for classes, but those are irrelevant here.

This is some example code from learning D:

```
import std.stdio;

void printArgs(T...)() if(T.length != 0) {
     foreach(sym; T)
         writeln(sym.stringof);
}

alias ArgList(T...) = T;

void main() {
     printArgs!(int, "Pizza!", std.stdio, writeln);
     printArgs!(ArgList!(int, string, double));
}
```

AliasSeq is implemented like ArgList, which is the shortened form 
of the following:

```
template ArgList(T...) {
    alias ArgList = T;
}
```

Normally, T... is only visible inside the template body, but the 
eponymous alias gives you a handle to it externally.


More information about the Digitalmars-d-learn mailing list