UDA syntax

Era Scarecrow rtcvb32 at yahoo.com
Wed Jan 16 21:45:31 PST 2013


On Thursday, 17 January 2013 at 04:38:14 UTC, Ali Çehreli wrote:
> On 01/16/2013 05:59 PM, Joseph Cassman wrote:
>> I was wondering what the syntax is for user defined attributes 
>> (I.e. bug 9222) implemented in release 2.061. I was still 
>> unclear after reading the thread 
>> forum.dlang.org/thread/k7afq628321 at digitalmars.com.
>>
>> Thanks for the help
>>
>> Joseph
>
> The following is the code that I had used for experimenting 
> with UDAs:

  This is by far the most comprehensive explanation of how to use 
them that I've seen so far. Still a couple questions.

  Do the structs have to be empty? (Do they have to be structs?) 
If they don't and you add code, can that code help/add or modify 
the attributed object (or can it at all?).

  Seems somehow in my mind there's two approaches to how the 
attributes work

  Define in one place, it modifies what it attaches to. This would 
be good for like serialization, perhaps adding unique functions 
for a particular set of jobs.

  struct Serialize {
  //assuming it's mixed in similar to a mixin template.
    void write(R)()
    if (isOutputRange!(R)) {
      //foreach over all elements and and save them, or
      //on items marked with an attribute to be saved
    }
  }

  @Serialize struct S {
    //write appended in silently from UDA
    int x;
  }

  Used definition(s) where functions need to (statically) 
recognize them to interact with them. This is what currently it 
seems like it's doing, which is simpler to understand and 
integrate, but somehow only feels like half the formula.

  struct Serialize {}

  struct S {
      @Serialize int x;
  }

  void write(R, S)(R outputRange, S inputStruct)
  if (isOutputRange!(R)) {
     //foreach, if variable(s) have @Serialize then we write it.
  }


More information about the Digitalmars-d-learn mailing list