Challenge

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Tue Oct 4 19:15:13 PDT 2016


On Wednesday, October 05, 2016 11:20:44 Manu via Digitalmars-d wrote:
> > While you're at it, might I suggest also adding std.traits.isProperty?
> >
> >  Something like:
> > template isProperty(T, string member)
> > {
> >
> >   import std.meta : AliasSeq;
> >   import std.traits : FunctionTypeOf;
> >   alias sym = AliasSeq!(__traits(getMember, T, member))[0];
> >   enum isProperty = !is(typeof(sym) == function) &&
> >
> > is(FunctionTypeOf!(typeof(&sym)) == function);
> > }
>
> Why this AliasSeq business? That line is rather an abomination... why
> are all these horrible expressions popping up as recommendations
> nowadays?

The AliasSeq muck is there because for some reason you can't alias the
result of __traits, so doing something like

alias sym = __traits(getMember, T, member);

isn't legal. So, this has nothing to do with a recommendation of best
practice and everything to do with an annoying bug.

https://issues.dlang.org/show_bug.cgi?id=7804

It _is_ however recommended to use __traits(getMember, T, member) over
manually building it with strings with something like T.stringof ~ "." ~
member, because the string manipulation falls about in corner cases (e.g. it
could result in a symbol conflict). It's just that then has the unfortunate
side effect of requiring AliasSeq because of the bug.

- Jonathan M Davis



More information about the Digitalmars-d mailing list