User Defined Attributes
bearophile
bearophileHUGS at lycos.com
Tue Nov 6 08:23:30 PST 2012
For the syntax maybe it's better something like @() instead of
[], so it becomes more greppable and more easy to tell apart
visually from the array literals:
@(1, "xx", Foo) int x;
Supporting annotations for function arguments is probably an
important sub-feature.
Yesterday I was discussing about the bug-prone nature of foreach
loops on a struct array, and one of the solutions I've suggested
was a user-defined annotation for the programmer to denote that
she wants to modify just the copy:
struct Foo {}
Foo[10] foos;
foreach (@copy f; foos) { ... }
With UDA syntax:
foreach ([Copy] f; foos) { ... }
Or:
foreach (@(Copy) f; foos) { ... }
But I think there's no way to tell the compiler to give a
compile-time error if such annotation is not present there
(unless there's "ref").
---------------------
Gor Gyolchanyan:
> @flags enum A { ... }
>
> the "flags" attribute would replace the declaraction of A with
> another enum declaration with the same name and same members,
> but with replaced initialization and would static assert(false,
> "flags enum can't have initializers") if any initializers are
> given.
I appreciate your idea (I think of user-defined attributes also
as ways to extend the type system), But I know the engineer in
Walter prefers extra-simple ideas, so maybe your idea will not be
accepted :-) But let's see.
Bye,
bearophile
More information about the Digitalmars-d-announce
mailing list