So, User-Defined Attributes

Era Scarecrow rtcvb32 at yahoo.com
Fri Jan 4 12:33:03 PST 2013


On Friday, 4 January 2013 at 15:45:21 UTC, Philippe Sigaud wrote:
> OK, now that 2.061 is out, we have User-Defined Attributes 
> (UDAs).
>
> Except, there is no doc on them, no explanation, nothing. For 
> people who did not follow the monstrous threads in November, 
> it's as if UDA do not exist.

> ...

> Here is the executive summary:
>
> User Defined Attributes (UDA) are compile time expressions that 
> can be attached to a declaration. These attributes can then be 
> queried, extracted, and manipulated at compile time. There is 
> no runtime component to them.

  This is sorta like tuples; But from the brief summaries I cannot 
fully understand how or where they would be used. I understand 
some attributes can be made and added that some compilers may use 
(@noreturn as an example), but outside of the compiler I'd need 
an example of how to make use of them.

  Since there's no runtime component, then aside from carrying a 
tuple and some information forward at compile-time, what else can 
it do? How would you use it? Are there any special tuple formats 
that give information to automatically be included/compiled into 
the structs/classes without having to resort to mixins?



  Curiously enough it seems like @clone would be a useful example. 
Let's assume we want to write @clone, it's meaning that rather 
than writing a custom postblit to it's done automatically.

  struct S {
    string identifier;
    int value;
    string[] attributes; // @clone

    this(this) {attributes = attributes.dup;}
  }

  Normally you'd write a this(this) as above, but if we used UDA's 
how could it be used/implemented?


More information about the Digitalmars-d mailing list