| Thread overview | |||||
|---|---|---|---|---|---|
|
June 22, 2018 How do I filter out this type? | ||||
|---|---|---|---|---|
| ||||
In the below code, "A[] found" is never printed. What's the proper way to check for this type?
import std.stdio;
import std.traits : FieldNameTuple;
class A { }
class B
{
string foo;
string baa;
A[] list;
}
void main()
{
static foreach(field; FieldNameTuple!B)
{
static if(is(typeof(__traits(getMember, B, field) == A[])))
{
writeln("A[] found");
}
}
writeln("done");
}
| ||||
June 22, 2018 Re: How do I filter out this type? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Dr.No | On 6/22/18 1:07 PM, Dr.No wrote: > static if(is(typeof(__traits(getMember, B, field) == A[]))) static if(is(typeof(__traits(getMember, B, field)) == A[])) Note the slight change in parentheses. -Steve | |||
June 23, 2018 Re: How do I filter out this type? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Friday, 22 June 2018 at 17:20:03 UTC, Steven Schveighoffer wrote:
> On 6/22/18 1:07 PM, Dr.No wrote:
>> static if(is(typeof(__traits(getMember, B, field) == A[])))
> static if(is(typeof(__traits(getMember, B, field)) == A[]))
>
> Note the slight change in parentheses.
>
> -Steve
oh, I'm a bit embarrassed. haha Thanks anyway!
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply