digitalmars.D - Relative Aliases?
- Jonathan Marler (45/45) May 28 2017 Is there a way to get an alias to a symbol relative to the
- Timon Gehr (2/8) May 28 2017 __traits(parent,{})
- Jonathan Marler (2/10) May 28 2017 THANK YOU!!
- tsbockman (3/13) May 28 2017 For types, you can use `typeof(this)` (or `typeof(cast() this)`
Is there a way to get an alias to a symbol relative to the current location? I'm looking for a general solution but I'll show an example to demonstrate one use case. Say we want to access the alias to the current function symbol. Obviously we can use the name of the current function, i.e. void foo() { alias TheAliasWeWant = foo; } but this means the code must be modified for every function, i.e. void foo1() { alias TheAliasWeWant = foo1; } void foo2() { alias TheAliasWeWant = foo1; // uh oh, should be foo2, copy paste error } is there a way to implement a library function/template that can do this? void foo1() { alias TheAliasWeWant = currentFunctionAlias(); } void foo2() { alias TheAliasWeWant = currentFunctionAlias(); // can't make copy/paste error } Note that this is similar to the special keywords like __FUNCTION__, __MODULE__, the difference being that we want a symbol instead of a string. We may be able to create an interesting solution to the function case where we unmangle the __FUNCTION__ result and then mixin the resulting string, but I'm also looking for the ability to get an alias to the current type, i.e. struct Foo { void foo() { alias TheAliasWeWant = Foo; alias TheAliasWeWant = currentTypeAlias(); // possible? } }
May 28 2017
On 28.05.2017 17:04, Jonathan Marler wrote:Is there a way to get an alias to a symbol relative to the current location? I'm looking for a general solution but I'll show an example to demonstrate one use case. Say we want to access the alias to the current function symbol. ...__traits(parent,{})
May 28 2017
On Sunday, 28 May 2017 at 15:07:55 UTC, Timon Gehr wrote:On 28.05.2017 17:04, Jonathan Marler wrote:THANK YOU!!Is there a way to get an alias to a symbol relative to the current location? I'm looking for a general solution but I'll show an example to demonstrate one use case. Say we want to access the alias to the current function symbol. ...__traits(parent,{})
May 28 2017
On Sunday, 28 May 2017 at 15:04:15 UTC, Jonathan Marler wrote:I'm also looking for the ability to get an alias to the current type, i.e. struct Foo { void foo() { alias TheAliasWeWant = Foo; alias TheAliasWeWant = currentTypeAlias(); // possible? } }For types, you can use `typeof(this)` (or `typeof(cast() this)` if you want to strip type qualifiers).
May 28 2017