digitalmars.D.learn - Capturing Caller UDAs as CT Template Function Parameters
- "Per =?UTF-8?B?Tm9yZGzDtnci?= <per.nordlow gmail.com> (14/14) May 18 2015 As a follow up to the most
- "Per =?UTF-8?B?Tm9yZGzDtnci?= <per.nordlow gmail.com> (5/6) May 18 2015 To clarify: Instead of *string* `__FUNCTION__` I instead want a
- "Per =?UTF-8?B?Tm9yZGzDtnci?= <per.nordlow gmail.com> (3/8) May 18 2015 I'm gonna try the tips here:
- "Per =?UTF-8?B?Tm9yZGzDtnci?= <per.nordlow gmail.com> (8/16) May 18 2015 void yield(T)(ref T value)
- anonymous (14/21) May 18 2015 You have to import the module, too:
As a follow up to the most http://forum.dlang.org/thread/miri9k$2p5$1 digitalmars.com I'm now very much interested in finding a way to make yield() capture the UDAs of its caller. That is instead of void yield(T)(ref T value) I want it to get a hold of the UDAs of the calling function and somehow propagate them as compile-time template arguments. Something like void yield(T, callerAttributes = __traits(getAttributes, __FUNCTION__))(ref T value) The problem with this is that __FUNCTION__ is a string when getAttributes expects a symbol. Can I somehow can a hold of the symbol of the caller. Is this doable somehow?
May 18 2015
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 ;)
May 18 2015
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-learn puremagic.com
May 18 2015
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: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?! ;)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-learn puremagic.com
May 18 2015
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.
May 18 2015