<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#ffffff" text="#000000">
    Am 02.04.2011 04:00, schrieb Caligo:
    <blockquote
      cite="mid:AANLkTin+geQ5Np0g0pVWceS_cA55UJTAduT84cd5N7mx@mail.gmail.com"
      type="cite">
      <pre wrap="">On Fri, Apr 1, 2011 at 5:14 PM, enuhtac <a class="moz-txt-link-rfc2396E" href="mailto:enuhtac_lists@gmx.de"><enuhtac_lists@gmx.de></a> wrote:
</pre>
      <blockquote type="cite">
        <pre wrap="">Hello,

the "is" expression is a great feature of D - but its use is not very
intuitive, at least for me.
I'm trying to write a template that figures out if the template
parameter is of a given type.
This is the type I would like to check for:

struct A( T, string s )
{ ... };

One possibility to accomplish this check is explicit template
specialization:

template isA( T )
{
   enum bool isA = false;
};

template isA( T : A!( U, s ), U, string s )
{
   enum bool isA = true;
};

This more or less the C++ approach. But in D this could also be done
with static if and the "is" expression. As I understand "is" it should
be done like this:

template isA( T )
{
   static if( is( T U == A!( U, s ), string s ) )
       enum bool isA = true;
   else
       enum bool isA = false;
};

But this does not work. So what am I doing wrong?

Regards,
enuhtac


</pre>
      </blockquote>
      <pre wrap="">
I'm new too, but I think it should be like this:

template isA( T ){

  enum bool isA = is(T : A)
}

if the name of enum is same as the template then you could use it as such:

if( isA( T ) ){ }

instead of

if( isA( T ).isA ){ }

Also note that : allows implicit conversion, while == requires the
types to be exactly the same.
</pre>
    </blockquote>
    Your right. In your example it is possible to circumvent the "static
    if" construct. I was not aware of this, so thanks for the hint.<br>
    But in my case this does not work as I'm using the following "is"
    form:<br>
    <br>
    <b>is (</b> <i>Type</i> <i>Identifier</i> <b>==</b> <i>TypeSpecialization</i>
    <b>,</b> <i>TemplateParameterList</i> <b>)<br>
      <br>
    </b>Obviously "is" forms that include an "Identifier" can only be
    used in "static if" constructs. Actually I could do without the
    "Identifier" but I need the "TemplateParameterList". But there is no
    "is" form where you get a "TemplateParameterList" without an
    "Identifier".<br>
    Actually that would be nice as this would look like the explicit
    specialization:<br>
    <pre wrap="">template isA( T )
{
   static if( is( T == A!( U, s ), U, string s ) )
       enum bool isA = true;
   else
       enum bool isA = false;
};</pre>
    Or with your simplification:<br>
    <pre wrap="">template isA( T )
{
   enum bool isA = is( T == A!( U, s ), U, string s );
};

</pre>
    But this is not possible as the "Identifier" is missing.<br>
    <br>
    So still I do not know what I'm doing wrong in my original code.<br>
  </body>
</html>