digitalmars.D.learn - comma inside is expression
- Jos van Uden (13/13) Mar 14 2012 I've been reading the tutorial on templates and found this example:
- Nathan M. Swan (3/18) Mar 14 2012 It's documented on the language reference:
- Philippe Sigaud (10/22) Mar 17 2012 =99s recurse down.
I've been reading the tutorial on templates and found this example: template rank(T) { static if (is(T t == U[], U)) // is T an array of U, for some type U? enum rank = 1 + rank!(U); // then let’s recurse down. else enum rank = 0; // Base case, ending the recursion. } TDPL never mentions the use of a comma operator inside an is expression. Is this an undocumented feature? Also the symbol 't' is never used, but if I remove it, it won't compile. It's a really good tutorial, but I find this particular example puzzling. Jos
Mar 14 2012
On Thursday, 15 March 2012 at 02:34:45 UTC, Jos van Uden wrote:I've been reading the tutorial on templates and found this example: template rank(T) { static if (is(T t == U[], U)) // is T an array of U, for some type U? enum rank = 1 + rank!(U); // then let’s recurse down. else enum rank = 0; // Base case, ending the recursion. } TDPL never mentions the use of a comma operator inside an is expression. Is this an undocumented feature? Also the symbol 't' is never used, but if I remove it, it won't compile. It's a really good tutorial, but I find this particular example puzzling. JosIt's documented on the language reference: http://dlang.org/expression.html#IsExpression
Mar 14 2012
On Thu, Mar 15, 2012 at 03:34, Jos van Uden <user domain.invalid> wrote:I've been reading the tutorial on templates and found this example: template rank(T) =C2=A0{ =C2=A0 =C2=A0static if (is(T t =3D=3D U[], U)) // is T an array of U, for=some type U?=C2=A0 =C2=A0 =C2=A0 =C2=A0enum rank =3D 1 + rank!(U); // then let=E2=80==99s recurse down.=C2=A0 =C2=A0else =C2=A0 =C2=A0 =C2=A0 =C2=A0enum rank =3D 0; // Base case, ending the recu=rsion.} TDPL never mentions the use of a comma operator inside an is expression. Is this an undocumented feature? Also the symbol 't' is never used, but if I remove it, it won't compile. It's a really good tutorial, but I find this particular example puzzling.Yes, the is() expression is puzzling in general. In fact, I rediscovered how quirky it was when writing the tutorial :) Nathan already gave you a link. I give it at the beginning of A.1, but I can see it's not really visible. I should change the link instruction to display the link as a footnote also= .
Mar 17 2012