digitalmars.D.learn - Adding UDA at compile time
- Andrea Fontana (3/3) Aug 26 2015 I wonder if there's a way to add UDA to functions at compile-time
- Alex Parrill (8/12) Aug 26 2015 What do you mean? UDAs are already specified at compile time.
- Andrea Fontana (6/19) Aug 26 2015 __traits(setAttributes, ...)
- Alex Parrill (17/22) Aug 26 2015 Lots of compile-time information is fixed after the symbol is
I wonder if there's a way to add UDA to functions at compile-time (so I can read later from other parts of application). Andrea
Aug 26 2015
On Wednesday, 26 August 2015 at 08:19:04 UTC, Andrea Fontana wrote:I wonder if there's a way to add UDA to functions at compile-time (so I can read later from other parts of application). AndreaWhat do you mean? UDAs are already specified at compile time. ("hello") void foo() { } static assert(__traits(getAttributes, foo)[0] == "hello");
Aug 26 2015
On Wednesday, 26 August 2015 at 14:01:00 UTC, Alex Parrill wrote:On Wednesday, 26 August 2015 at 08:19:04 UTC, Andrea Fontana wrote:__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, ...);I wonder if there's a way to add UDA to functions at compile-time (so I can read later from other parts of application). AndreaWhat do you mean? UDAs are already specified at compile time. ("hello") void foo() { } static assert(__traits(getAttributes, foo)[0] == "hello");
Aug 26 2015
On Wednesday, 26 August 2015 at 14:29:30 UTC, Andrea Fontana wrote:__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 ("hello"): void foo3() {} void foo4() {} Also if you're talking about the `export` keyword, then that's not a UDA.
Aug 26 2015