Challenge
Jonathan M Davis via Digitalmars-d
digitalmars-d at puremagic.com
Mon Oct 3 12:01:46 PDT 2016
On Monday, October 03, 2016 11:13:52 Jonathan M Davis via Digitalmars-d wrote:
> template isStaticMember(T, string member)
> {
> static if (!__traits(hasMember, T, member))
> enum bool isStaticMember = false;
> else
> {
> import std.meta : AliasSeq;
> import std.traits : FunctionTypeOf;
> alias sym = AliasSeq!(__traits(getMember, T, member))[0];
>
> static if (__traits(isStaticFunction, sym))
> enum bool isStaticMember = true;
> else static if (is(FunctionTypeOf!sym == function) &&
> is(FunctionTypeOf!(typeof(&sym)) == function))
> {
> enum bool isStaticMember = false;
> }
> else
> {
> enum bool isStaticMember = !__traits(compiles, sym.offsetof) &&
> __traits(compiles, &sym);
> }
> }
> }
Well, since I took the time to write it, I created a PR for it:
https://github.com/dlang/phobos/pull/4834
So, if anyone sees problems with my implementation, go poke holes in it.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list