Thread overview
Filter out common object functions
Mar 14, 2017
Inquie
Mar 14, 2017
Adam D. Ruppe
Mar 14, 2017
Inquie
March 14, 2017
I am iterating over the members of classes and interfaces and get things like hash, this, etc. These are causing problems in my code. I would like to get only the "specified" members.

While I can filter out

__traits(allMembers, T);

using Erase, it is tedius and error prone.

Is there a way to get only the immediate members? Non-inherited, and "common"(for a lack of a better word), this(), for example, is specified by the language... i don't need it, just functions the user specifies in the type.

March 14, 2017
On Tuesday, 14 March 2017 at 19:39:26 UTC, Inquie wrote:
> __traits(allMembers, T);

Try derivedMembers instead.
March 14, 2017
On Tuesday, 14 March 2017 at 19:43:59 UTC, Adam D. Ruppe wrote:
> On Tuesday, 14 March 2017 at 19:39:26 UTC, Inquie wrote:
>> __traits(allMembers, T);
>
> Try derivedMembers instead.

That doesn't work, unfortunately, probably because of the types I'm using(just returns object.

What I can do is this:

	enum isElementOfObject(alias T) = (staticIndexOf!(T, __traits(allMembers, Object)) < 0) ? true : false;
	enum isElementOfIDispatch(alias T) = (staticIndexOf!(T, __traits(allMembers, IDispatch)) < 0) ? true : false;	
	enum membersList = Filter!(isElementOfIDispatch, Filter!(isElementOfObject, __traits(derivedMembers, T)));


It would be nice if instead of having to make a large list of isElementOf____, I could pass the types to the predicate:


        enum isElementOf(alias S, alias T) = (staticIndexOf!(T, __traits(allMembers, S)) < 0) ? true : false;
	enum membersList = Filter!(isElementOf!Object, __traits(derivedMembers, T)));

and ultimately give a list of objects:


	enum membersList = Filter!(isElementOf!(Object, IDispatch), __traits(derivedMembers, T)));


Would be pretty cool if D could do that, but I doubt it can ;/ (not logically impossible, sort of like currying or something)