Re: Capturing Caller UDAs as CT Template Function Parameters
On Monday, 18 May 2015 at 21:00:20 UTC, Per Nordlöw wrote: Is this doable somehow? To clarify: Instead of *string* `__FUNCTION__` I instead want a reference to the *symbol* of the calling function scope typically passed as an alias parameter. We could of course always solve it with a mixin but that is 6+1 characters too many ;)
Re: Capturing Caller UDAs as CT Template Function Parameters
On Monday, 18 May 2015 at 21:35:44 UTC, Per Nordlöw wrote: void yield(T)(ref T value) { mixin(alias caller = ~ caller ~ ;); } doesn't work across module boundaries not even for `__PRETTY_FUNCTION__`. Do we need need to fix the compiler, Walter?! ;) You have to import the module, too: void yield(T, string caller_str = __FUNCTION__)(ref T value) { import std.array: join, split; enum module_str = caller_str.split(.)[0 .. $ - 1].join(.); mixin(static import ~ module_str ~ ;); mixin(alias caller = ~ caller_str ~ ;); } This fails for methods, of course. I guess you could remove elements from the back of __FUNCTION__ until it compiles as a module, and then import that.
Re: Capturing Caller UDAs as CT Template Function Parameters
On Monday, 18 May 2015 at 21:04:19 UTC, Per Nordlöw wrote: To clarify: Instead of *string* `__FUNCTION__` I instead want a reference to the *symbol* of the calling function scope typically passed as an alias parameter. We could of course always solve it with a mixin but that is 6+1 characters too many ;) I'm gonna try the tips here: http://forum.dlang.org/thread/mailman.160.1376790770.1719.digitalmars-d-le...@puremagic.com
Re: Capturing Caller UDAs as CT Template Function Parameters
On Monday, 18 May 2015 at 21:30:23 UTC, Per Nordlöw wrote: On Monday, 18 May 2015 at 21:04:19 UTC, Per Nordlöw wrote: To clarify: Instead of *string* `__FUNCTION__` I instead want a reference to the *symbol* of the calling function scope typically passed as an alias parameter. We could of course always solve it with a mixin but that is 6+1 characters too many ;) I'm gonna try the tips here: http://forum.dlang.org/thread/mailman.160.1376790770.1719.digitalmars-d-le...@puremagic.com void yield(T)(ref T value) { mixin(alias caller = ~ caller ~ ;); } doesn't work across module boundaries not even for `__PRETTY_FUNCTION__`. Do we need need to fix the compiler, Walter?! ;)