User Defined Attributes

Adam D. Ruppe destructionator at gmail.com
Wed Nov 7 15:43:38 PST 2012


On Wednesday, 7 November 2012 at 23:17:24 UTC, Walter Bright 
wrote:
> Doesn't putting compiler hooks in for them make them inherently 
> global?

One of the previous threads put forth something like this:

template MyAttribute(alias subject, T... arguments) { /* some 
implementation */

The attribute is a template that replaces the declaration. So you 
type:

[MyAttribute("foo")]
class Something {}


And the compiler rewrites that to:

class __anonymous_Something {}

alias Something = MyAttribute!(__anonymous_Something, "foo");



... or something like that. I'm going off memory here. But then 
you can use the template to do whatever you'd normally do with a 
template.

For some reason this feels incomplete to me. I know one of those 
proposals enabled something we can't really do now, whereas what 
I described here of course *can* be done now.


More information about the Digitalmars-d-announce mailing list