Comment #0 by dlang-bugzilla — 2023-05-12T21:21:41Z
/////////////////// test.d ///////////////////
struct BobsContext
{
void bobWhoAlreadyHasAContext(alias fun)()
{
fun(1);
}
}
void main()
{
BobsContext b;
// Works:
{
void fun(X)(X x) {}
b.bobWhoAlreadyHasAContext!fun();
}
// Doesn't work:
{
alias fun = function (x) {};
b.bobWhoAlreadyHasAContext!fun();
}
}
//////////////////////////////////////////////
(DMD currently produces the "function requires a dual-context" deprecation)
Leaving aside the question of why lambdas don't have their need for context auto-detected like normal template functions... if the user writes the keyword "function", that should effectively make the lambda static and not require a context.
If this somehow ends up too much of a breaking change... the "static" keyword is currently not accepted in lambda / anonymous function literals, but it could be.
Comment #1 by robert.schadek — 2024-12-13T19:28:57Z