Thread overview
Check type is a struct at compile time?
Dec 05, 2014
Gary Willoughby
Dec 05, 2014
Kapps
Dec 06, 2014
Jonathan M Davis
Dec 18, 2014
shona123
December 05, 2014
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
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
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
But how to do the same thing for a struct?


_____________________
dhoom