www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Check type is a struct at compile time?

reply "Gary Willoughby" <dev nomad.so> writes:
How can i check that a type is a struct at compile time? I know i 
can test for a class like this:

static if(is(T == class))
{
     ...
}

But how to do the same thing for a struct?
Dec 05 2014
next sibling parent "Kapps" <opantm2+spam gmail.com> writes:
On Friday, 5 December 2014 at 20:38:31 UTC, Gary Willoughby wrote:
 How can i check that a type is a struct at compile time? I know 
 i can test for a class like this:

 static if(is(T == class))
 {
     ...
 }

 But how to do the same thing for a struct?
Same thing but with struct: is(T == struct) Note that this returns false for things like 'int'. Ex: struct Foo { } void foo(T)(T inst) { static if(is(T == struct)) writeln(T.stringof, " is a struct"); else writeln(T.stringof, " is NOT a struct"); } void main() { Foo a; foo(a); foo(3); } -- Foo is a struct int is NOT a struct
Dec 05 2014
prev sibling parent reply Jonathan M Davis via Digitalmars-d-learn writes:
On Friday, December 05, 2014 20:38:30 Gary Willoughby via Digitalmars-d-learn
wrote:
 How can i check that a type is a struct at compile time? I know i
 can test for a class like this:

 static if(is(T == class))
 {
      ...
 }

 But how to do the same thing for a struct?
static if(is(T == struct)) { } - Jonathan M Davis
Dec 06 2014
parent "shona123" <ganibhai155 gmail.com> writes:
But how to do the same thing for a struct?


_____________________
dhoom
Dec 18 2014