www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How do I filter out this type?

reply Dr.No <jckj33 gmail.com> writes:
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");
}
Jun 22 2018
parent reply Steven Schveighoffer <schveiguy yahoo.com> writes:
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
Jun 22 2018
parent Dr.No <jckj33 gmail.com> writes:
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!
Jun 23 2018