Templates array detection

Ali Çehreli acehreli at yahoo.com
Wed Dec 12 07:21:16 PST 2012


On 12/12/2012 06:49 AM, Cube wrote:
 > Better example code for my other problem. How can I make the 3rd foo
 > work on Datas?
 >
 > --
 > struct Data(T)
 > {
 > T elem;
 > }

Data is a struct template, not a type (until instantiated).

 > void foo(T)(T t) if(is(T == Data)) // ?

This works:

void foo(T)(T t) if(is(T == Data!T))

 > {
 > if(is(T == Data!int))
 > writeln(t.elem + 1);
 > else if(is(T == Data!string))
 > writeln(t.elem);
 > }
 > --

Ali



More information about the Digitalmars-d-learn mailing list