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)
{
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.
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))
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[];
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
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
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.
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
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