www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Need is expression to match Variadic Template Class Type

reply d coder <dlang.coder gmail.com> writes:
--f46d04016d8f1f746104c1403eef
Content-Type: text/plain; charset=ISO-8859-1

Greetings

What would be the form of "is" expression to match with a Variadic Template
Class?
I am pasting a simple example below to clarify my need. I need an is
expression to match with the Bar(T...) type in the code below.

Regards
- Puneet

class Foo(int N=0) {}

class Bar(T...) {}

void foobar(L) (ref L l)
  if(is(L f : Foo!N, int N))
    {
      import std.stdio;
      writeln("Matched a Foo(int N)");
    }

void foobar(L) (ref L l)
  if // WHAT IS EXPRESSION SHOULD COME HERE
    {
      import std.stdio;
      writeln("Matched a Bar(T...)");
    }

void main() {
  Foo!0 foo = new Foo!0();
  Bar!() bar = new Bar!();
  foobar(foo);
  foobar(bar);
}

--f46d04016d8f1f746104c1403eef
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Greetings<div><br></div><div>What would be the form of &quot;is&quot; expre=
ssion to match with a Variadic Template Class?</div><div>I am pasting a sim=
ple example below to clarify my need. I need an is expression to match with=
 the Bar(T...) type in the code below.</div>

<div><br></div><div>Regards</div><div>- Puneet</div><div><br></div><div><di=
v>class Foo(int N=3D0) {}</div><div><br></div><div>class Bar(T...) {}</div>=
<div><br></div><div>void foobar(L) (ref L l)</div><div>=A0 if(is(L f : Foo!=
N, int N))</div>

<div>=A0 =A0 {</div><div>=A0 =A0 =A0 import std.stdio;</div><div>=A0 =A0 =
=A0 writeln(&quot;Matched a Foo(int N)&quot;);</div><div>=A0 =A0 }</div><di=
v><br></div><div>void foobar(L) (ref L l)</div><div>=A0 if // WHAT IS EXPRE=
SSION SHOULD COME HERE</div>

<div>=A0 =A0 {</div><div>=A0 =A0 =A0 import std.stdio;</div><div>=A0 =A0 =
=A0 writeln(&quot;Matched a Bar(T...)&quot;);</div><div>=A0 =A0 }</div><div=
<br></div><div>void main() {</div><div>=A0 Foo!0 foo =3D new Foo!0();</div=
<div>=A0 Bar!() bar =3D new Bar!();</div>

<div>=A0 foobar(foo);</div><div>=A0 foobar(bar);</div><div>}</div></div><di= v><br></div> --f46d04016d8f1f746104c1403eef--
May 30 2012
parent "Simen Kjaeraas" <simen.kjaras gmail.com> writes:
On Wed, 30 May 2012 14:38:50 +0200, d coder <dlang.coder gmail.com> wrote:

 Greetings

 What would be the form of "is" expression to match with a Variadic  
 Template
 Class?
 I am pasting a simple example below to clarify my need. I need an is
 expression to match with the Bar(T...) type in the code below.

 Regards
 - Puneet

 class Foo(int N=0) {}

 class Bar(T...) {}

 void foobar(L) (ref L l)
   if(is(L f : Foo!N, int N))
     {
       import std.stdio;
       writeln("Matched a Foo(int N)");
     }

 void foobar(L) (ref L l)
   if // WHAT IS EXPRESSION SHOULD COME HERE

is(L unused : Bar!T, T...)
     {
       import std.stdio;
       writeln("Matched a Bar(T...)");
     }

 void main() {
   Foo!0 foo = new Foo!0();
   Bar!() bar = new Bar!();
   foobar(foo);
   foobar(bar);
 }

May 30 2012