Proposal: user defined attributes

Steven Schveighoffer schveiguy at yahoo.com
Fri Mar 16 09:57:25 PDT 2012


On Fri, 16 Mar 2012 09:35:54 -0400, Adam D. Ruppe  
<destructionator at gmail.com> wrote:

> On the ride over here today, I had a thought that
> I think neatly solves the user defined attribute
> question.
>
> enum Serializable { yes, no }
>
> @note(Serializable.yes) int a;

I thought @<symbol> was supposed to be a user-defined annotation.   
Otherwise, why did we introduce @syntax?

I'd rather see something like this:

@annotation serializable(bool x = true) {return x ? Serializable.yes :  
Serializable.no;}  // implicit auto

@serializable int a;
@serializable(false) int b;

Where annotations have to be CTFE-able (because they are constructed at  
compile-time)

-Steve


More information about the Digitalmars-d mailing list