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

Steven Schveighoffer schveiguy at gmail.com
Wed Jan 15 20:27:18 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:
> ```
>
> ```

Is there something missing here? Hard to understand the rest 
without it.


> 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{}.

That is not valid syntax AFAIK.

> 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.)

Also seems like invalid syntax. Where does this come from?

>
> Anyone can explain me what
> ```d
> template f(Specs...)f(T.init);
> ```
> means?

I think it's meant to be a documentation thing, or AST printout 
(which isn't always valid syntax)? It's not valid declaration 
syntax, template requires {}.

-Steve


More information about the Digitalmars-d-learn mailing list