Thread overview | ||||||
---|---|---|---|---|---|---|
|
December 05, 2014 Check type is a struct at compile time? | ||||
---|---|---|---|---|
| ||||
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? |
December 05, 2014 Re: Check type is a struct at compile time? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Gary Willoughby | 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
|
December 06, 2014 Re: Check type is a struct at compile time? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Gary Willoughby | 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
|
December 18, 2014 Re: Check type is a struct at compile time? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | But how to do the same thing for a struct? _____________________ dhoom |
Copyright © 1999-2021 by the D Language Foundation