There are some special typeof() implementations, typeof(this), typeof(super), etc, which may be used within the scope of a class to query these important details.
I'm frequently finding myself needing something like typeof(function), which would be valid within the scope of any function/method and produce its type.
I'm frequently finding myself needing to use mixins within a function which need to know information about the functions arguments so that it can generate code that references them.
For instance, very useful when creating pass-through/proxy functions, but I have some other uses too.
Comment #1 by iamthewilsonator — 2019-06-10T09:13:05Z
So, typeof(this) and typeof(super) are just regular expression typeofs, typeof(return) is special because it needs deferred analysis when the return type is auto.
This would effectively be just as special, if not more so. Do you still need this?
Comment #2 by turkeyman — 2019-06-10T09:18:34Z
I have needed this many times, and I think it's an obvious hole, especially in contrast to the presence of all the others.
Comment #3 by b2.temp — 2019-06-10T13:08:13Z
What's needed is not a special typeof(function), but more a new symbol that represents the function we're in and that would work with typeof(). In addition it would be nice to have a special symbol that would represent the tuple of parameters.
using metaprog and __FUNCTION__ is known to work only when the current func has no overload.
Comment #4 by turkeyman — 2020-03-21T10:36:58Z
Yeah good point.
__FUNCTION__ really should have been that symbol you describe, then you could use __FUNCTION__.stringof or mangleof, or typeof(), etc...
Maybe introduce __function__ which is the symbol?
Comment #5 by dlang-bot — 2020-08-09T10:27:05Z
@NilsLankila created dlang/dmd pull request #11538 "add `__traits(getCurrentFunction)`" mentioning this issue:
- add `__traits(getCurrentFunction)`
- fix issue 8109
- fix issue 9306
This new traits is a shortcut allowing to call the function we
are in without using `mixin` and `__FUNCTION__` tricks.
https://github.com/dlang/dmd/pull/11538
Comment #6 by robert.schadek — 2024-12-13T17:59:57Z