Concerns about using struct initializer in UDA?

Andre Pany via Digitalmars-d digitalmars-d at puremagic.com
Fri May 12 13:20:37 PDT 2017


On Friday, 12 May 2017 at 19:33:52 UTC, ag0aep6g wrote:
> On 05/12/2017 09:01 PM, Andre Pany wrote:
>> [...]
> [...]
>>>  [...]
> [...]
>> [...]
>
> You can create the attribute separately:
>
>     enum Field a = { locationName: "B" };
>     @a int c;
>
> Or if avoiding the extra symbol is more important than beauty, 
> call a function literal:
>
>     @((){ Field a = { locationName: "B" }; return a; }()) int c;
>
> That's not as succinct as the syntax you propose, of course.
>
> But your syntax (`@A = {locationName: "B"} int c;`) misses an 
> important detail: There's no indication what the type of the 
> attribute is (or is `A` supposed to be the type?). To make it 
> work, you will have to add that. Something like 
> `@Field(locationName: "B")` or `@Field{locationName: "B"}` or 
> whatever works.
>
> At that point, why limit it to attributes? Constructors like 
> that would be nice everywhere. I remember such syntax being 
> discussed repeatedly, but I don't know where we stand. Maybe 
> there's a DIP already?

Yes, A is supposed to be the type. I have included the equal sign 
to to match the existing struct initializer as far as possible.

I would like to limit the dip to increase the chances the dip is 
accepted.

Kind regards
André


More information about the Digitalmars-d mailing list