Challenge

Manu via Digitalmars-d digitalmars-d at puremagic.com
Mon Oct 3 07:26:38 PDT 2016


On 3 October 2016 at 23:48, Manu <turkeyman at gmail.com> wrote:
> On 3 October 2016 at 23:41, Manu <turkeyman at gmail.com> wrote:
>> I'm finding this rather annoying:
>>
>> struct S
>> {
>>   static @property int p() { return 10; }
>> }
>>
>> pragma(msg, typeof(&S.p)); // prints: int function() @property
>> pragma(msg, is(typeof(&S.p) == function)); // prints: false
>>
>> It looks like a function... but I can't identify it as a function!
>
> I guess that should read: is(typeof(&S.p) == R function(A), R, A...)) ??


Here's a leg-up:

template isStaticMember(T, string member)
{
  mixin("alias M = T." ~ member ~ ";");
  static if(__traits(compiles, &M))
  {
    static if(!is(typeof(M) == function))
    {
      static if(is(typeof(&M) == R function(A), R, A...))
      {
        import std.traits : functionAttributes, FunctionAttribute;
        enum isStaticMember = (functionAttributes!M &
FunctionAttribute.property) && /* distinguish static/non-static
@property somehow */ */;
      }
      else
        enum isStaticMember = true;
    }
    else
    {
      enum isStaticMember = __traits(isStaticFunction, M);
    }
  }
  else
    enum isStaticMember = false;
}


More information about the Digitalmars-d mailing list