Proposal: user defined attributes

Jacob Carlborg doob at me.com
Wed Mar 21 01:08:11 PDT 2012


On 2012-03-21 01:35, Adam D. Ruppe wrote:
> On Wednesday, 21 March 2012 at 00:03:28 UTC, James Miller wrote:
> So you'd just very simply do:
>
> struct MyAttribute { bool activated; }
>
> // @note is just like doing internalTuple ~= MyAttribute(true)
> // and MyAttribute is of course just a plain old struct
> initializer
> @note(MyAttribute(true)) int a;
>
> To check it:
>
> foreach(note; __traits(getNotes, member_a))
> static if(is(typeof(note) == MyAttribute) {
> // do what you want here, ignore types you don't know
> }

That's basically my initial proposal and how annotations work in Java.

>> What data can be packed into annotations?
>
> Being able to use custom types is an
> important part of my idea here.

I think any type that a template can take (as a value) + other 
attributes/annotations.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list