Challenge
John Colvin via Digitalmars-d
digitalmars-d at puremagic.com
Mon Oct 3 07:25:57 PDT 2016
On Monday, 3 October 2016 at 13:19:19 UTC, Manu wrote:
> Fill in the blank...
> I'm having a really hard time with this. I've made it work with
> a
> mountain of code, and I want to see what others come up with...
template isStaticMember(T, string member)
{
mixin(`alias mem = T.` ~ member ~ `;`);
import std.traits : FunctionTypeOf;
static if (is(FunctionTypeOf!mem == function) &&
is(FunctionTypeOf!(typeof(&mem)) == function))
enum bool isStaticMember = __traits(isStaticFunction,
mem);
else
enum bool isStaticMember = is(typeof(&mem));
}
Basically, using FunctionTypeOf catches @property functions
(which just typeof wouldn't), but it also catches member
variables with function types, so we need the second
FunctionTypeOf to see if it's still a function when you take its
address (true for member functions, including @property
functions, not true for member variables with function types).
Everything else is just "can you take the address of this".
More information about the Digitalmars-d
mailing list