Template declaration of std.typecons.isTuple in -X JSON file.

monkyyy crazymonkyyy at gmail.com
Wed Jan 15 17:56:39 UTC 2025


On Wednesday, 15 January 2025 at 12:01:21 UTC, realhet wrote:
> Hello,
>
> I'm working on understanding and automating the contents of an 
> X Json file generated by LDC2.
> I'm testing it by processing the whole Phobos lib.
>
> The weirdest thing that I've found is this:
> X Json:
> ```
>
> ```
> With my program, I transformed into this header source code:
> ```d
> public template isTuple(T) {enum isTuple = __traits(compiles, ()
> {
> template f(Specs...)f(T.init);
> }
> );}
> ```
>
> Then the parser in my custom IDE was stopped with error: It 
> can't handle template with the ';' ending.
> So I temporarily enabled that form, but I can't find that 
> template; form in the documentation. I only found info about 
> template{}.
>
> Later I've found that the "template f(Specs...)f(T.init);" 
> thing is also in the DDoc of the std.typecons.d module.
>
> ```d
> enum isTuple(T) = __traits(compiles, () { template 
> f(Specs...)f(T.init); } );
> ```
> (It's just embedded code in the json as a string. So it was the 
> same at me as well.)
>
> Anyone can explain me what
> ```d
> template f(Specs...)f(T.init);
> ```
> means?
>
> From now on, I will detect it as valid, but please help me 
> understand it.
>
> Thx in advance!

the defination of aliasSeq is `alias seq(T...)=T;` my defination 
of tuple is

```d
struct Tuple(T...){
   T expand;alias expand this;
}
```

to define templates you reuse the name to "return"; I cant spell 
remotely spell the term form the spec

```d
template foo(){
   enum foo=1;
}
assert(foo!()=1);
```

---

all together that looks like they define a tuple inline and 
return its init which I think is probably expanding in some 
strange way


More information about the Digitalmars-d-learn mailing list