digitalmars.D.learn - Check type is a struct at compile time?
- Gary Willoughby (7/7) Dec 05 2014 How can i check that a type is a struct at compile time? I know i
- Kapps (19/26) Dec 05 2014 Same thing but with struct: is(T == struct)
- Jonathan M Davis via Digitalmars-d-learn (5/12) Dec 06 2014 static if(is(T == struct))
- shona123 (3/3) Dec 18 2014 But how to do the same thing for a struct?
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
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
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
But how to do the same thing for a struct? _____________________ dhoom
Dec 18 2014