www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - comma inside is expression

reply Jos van Uden <user domain.invalid> writes:
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
next sibling parent "Nathan M. Swan" <nathanmswan gmail.com> writes:
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.

 Jos

http://dlang.org/expression.html#IsExpression
Mar 14 2012
prev sibling parent Philippe Sigaud <philippe.sigaud gmail.com> writes:
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=

 =C2=A0 =C2=A0 =C2=A0 =C2=A0enum rank =3D 1 + rank!(U); // then let=E2=80=

 =C2=A0 =C2=A0else
 =C2=A0 =C2=A0 =C2=A0 =C2=A0enum rank =3D 0; // Base case, ending the recu=

 }


 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