On Tuesday, 5 May 2020 at 18:19:00 UTC, Meta wrote:
mixin template magic()
{
alias CallerRet = typeof(return);
CallerRet magic()
{
return CallerRet.init;
}
}
Small edit: you can remove the "CallerRet" alias by doing the
following:
mixin template magic()
{
typeof(return) magic()
{
return typeof(return).init;
}
}
Though I wouldn't really recommend it as it's very confusing,
IMO. This works because "typeof(return)" in the return position
here refers to the caller's scope, while "typeof(return)" inside
the function refer's to the function's scope.