Aliasing current function template instance
Jean-Louis Leroy
jl at leroy.nyc
Fri May 1 20:28:58 UTC 2020
Is it possible, inside a function template, to create an alias to
the instantiated function? IOW the equivalent of __FUNCTION__,
but yielding an alias?
The closest I came is:
import std.string;
import std.traits;
void foo(T)(lazy T)
{
mixin(
"alias thisFunction = ",
__FUNCTION__[0..__FUNCTION__.lastIndexOf('.')],
";");
pragma(msg, Parameters!thisFunction);
}
void main()
{
foo(0);
foo("");
}
dmd -c aliasthisfunction.d
(lazy int)
(lazy string)
...but (unsurprisingly) this fails in presence of overloads. I.e.
if I throw in:
void foo(T)(int, T);
...then I get:
aliasthisfunction.d(6): Error: template `aliasthisfunction.foo`
matches more than one template declaration:
aliasthisfunction.d(4): `foo(T)(lazy T)`
and
aliasthisfunction.d(20): `foo(T)(int, T)`
...
Something I have overlooked? Any ideas?
More information about the Digitalmars-d-learn
mailing list