Adding UDA at compile time

Alex Parrill via Digitalmars-d-learn digitalmars-d-learn at
Wed Aug 26 10:24:33 PDT 2015

On Wednesday, 26 August 2015 at 14:29:30 UTC, Andrea Fontana 
> __traits(setAttributes, ...)
> It would be useful, for example, if I have a list of functions 
> to mark. Let's say
> enum toExport = ["oldFunction", "thisToo"];
> foreach(d; toExport) __traits(setAttributes, ...);

Lots of compile-time information is fixed after the symbol is 
defined, making it effectively immutable. There's not, for 
example, a `__traits(setType, var)`.

If you want to apply a UDA to many functions at once, you can use 
the block syntax:

	@("hello") {
		void foo1() {}
		void foo2() {}

	// or alternatively


	void foo3() {}
	void foo4() {}

Also if you're talking about the `export` keyword, then that's 
not a UDA.

More information about the Digitalmars-d-learn mailing list