Concerns about using struct initializer in UDA?
Nicholas Wilson via Digitalmars-d
digitalmars-d at puremagic.com
Fri May 12 03:23:34 PDT 2017
On Thursday, 11 May 2017 at 10:49:58 UTC, Andre Pany wrote:
> Hi,
>
> I know there are concerns about struct initialization in method
> calls but what is about struct initializer in UDA?
>
> Scenario: I want to set several UDA values. At the moment I
> have to create for each value a structure with exactly 1 field.
> But it would be quite nice if I could use struct initialization
> to group these values:
>
> struct Field
> {
> string location;
> string locationName;
> }
>
> struct Foo
> {
> @A = {locationName: "B"} int c; // <------------------
> }
>
> void main() {}
>
> Of course the syntax is questionable, it is just a proposal.
> What do you think?
>
> Kind regards
> André
I'm not sure if it isi what you're looking for but you can do
struct Field
{
string location;
string locationName;
}
struct Foo
{
@Field("","B") int c;
}
We use this for our compiler recognised attributes in LDC, see
llvmAttr for an example
(https://github.com/ldc-developers/druntime/blob/ldc/src/ldc/attributes.d#L108)
More information about the Digitalmars-d
mailing list