generating @property from structs

Nicholas Wilson iamthewilsonator at hotmail.com
Sat Sep 30 08:20:44 UTC 2017


struct MyType
{
     void* ptr;
     static struct Info
     {
         @(42) int foo;
     }

     // Should be generated by the mixin below
     @property int foo()
     {
          int ret;
          getMyTypeInfo(ptr,42,int.sizeof,&ret);
          return ret;
     }
     mixin generateInfo!getMyTypeInfo;
}

extern(C) void getMyTypeInfo(void*,int, size_t,void*);

How do I write generateInfo info?

mixin template generateInfo(alias func)
{
     foreach(field; typeof(this).Info.tupleof)
     {
         //???
     }
}

I know I'll probably have to resort to string mixins, but how do 
I get the attribute so that I call
func(ptr,attibute, T.sizeof, &ret)? There will be a couple of 
values that dont have an attribute but they are all of known 
types and I want to handle them separately.

Thanks
Nic



More information about the Digitalmars-d-learn mailing list