Using traits get a list of methods and filter out the member vars.

2013-09-08 Thread Gary Willoughby
When iterating through class members using traits how do you filter out the member vars to only get a list of methods. I think i've solved it in the code below but it feels like i am abusing MemberFunctionsTuple. Is this the correct way to do this? private template Methods(T, int index = 0) {

Re: Using traits get a list of methods and filter out the member vars.

2013-09-08 Thread Dicebot
Key part here is is(T == function) - because of D type system funny properties only possible way to get T that matches that condition is to do `typeof` from declared function/method symbol. That type can't be manually expressed and thus used for member variable.

Re: Using traits get a list of methods and filter out the member vars.

2013-09-08 Thread Dicebot
http://dpaste.dzfl.pl/c250e798 import std.traits, std.range; private template Methods(T) if (is(T == class)) { private string[] getMethods() { string result[]; foreach (member_string; __traits(allMembers, T))

Re: Using traits get a list of methods and filter out the member vars.

2013-09-08 Thread Gary Willoughby
On Sunday, 8 September 2013 at 13:46:26 UTC, Dicebot wrote: http://dpaste.dzfl.pl/c250e798 import std.traits, std.range; private template Methods(T) if (is(T == class)) { private string[] getMethods() { string result[];

Re: Using traits get a list of methods and filter out the member vars.

2013-09-08 Thread Dicebot
On Sunday, 8 September 2013 at 16:43:16 UTC, Gary Willoughby wrote: This looks like a nice solution but i get errors when used across modules. The problem is that allmembers emits private members so across modules they are not available. You want to list private members or want them ignored

Re: Using traits get a list of methods and filter out the member vars.

2013-09-08 Thread Gary Willoughby
On Sunday, 8 September 2013 at 17:07:57 UTC, Dicebot wrote: On Sunday, 8 September 2013 at 16:43:16 UTC, Gary Willoughby wrote: This looks like a nice solution but i get errors when used across modules. The problem is that allmembers emits private members so across modules they are not

Re: Using traits get a list of methods and filter out the member vars.

2013-09-08 Thread Adam D. Ruppe
Something along the lines of static if(__traits(compiles, __traits(getMember, Foo, member)) static if(is(__traits(getMember, Foo, member) == function)) { // use it } The __traits(compiles, ...) is my go-to thingy for filtering out random errors.

Re: Using traits get a list of methods and filter out the member vars.

2013-09-08 Thread Jacob Carlborg
On 2013-09-08 18:43, Gary Willoughby wrote: This looks like a nice solution but i get errors when used across modules. The problem is that allmembers emits private members so across modules they are not available. I'm wondering if it tries to call the method here: static if

Re: Using traits get a list of methods and filter out the member vars.

2013-09-08 Thread Dicebot
On Sunday, 8 September 2013 at 19:48:31 UTC, Jacob Carlborg wrote: I'm wondering if it tries to call the method here: static if (is(typeof(member) == function)) Since D allows to call methods without parentheses. No, not in typeof. It will try to call it with `member.stringof` though, thus