On Friday, 1 May 2020 at 20:43:05 UTC, Steven Schveighoffer wrote:
On 5/1/20 4:28 PM, Jean-Louis Leroy wrote:
Something I have overlooked? Any ideas?
This trick works. No idea who came up with it:
alias thisFunction = __traits(parent, {});
-Steve
I think I get the idea. Alas it doesn't work inside a function
template, because it returns the template, not the instance:
void foo(T)(lazy T)
{
alias thisFunction = __traits(parent, {});
pragma(msg, thisFunction.stringof);
//pragma(msg, Parameters!thisFunction); // later
}
void main()
{
foo(0);
foo("");
}
prints:
foo(T)(lazy T)
foo(T)(lazy T)
Uncommenting the line that is (more or less) my real goal:
aliasthisfunction.d(7): Error: template instance
`std.traits.Parameters!(foo)` does not match template declaration
`Parameters(func...)`
with `func = (foo(T)(lazy T))`
must satisfy the following constraint:
` isCallable!func`