[dmd-internals] opApply with alias instead of delegate?
David Simcha
dsimcha at gmail.com
Sun Jan 9 12:03:27 PST 2011
I found this goodie in opover.c of the DMD source, and am wondering
if/when it will be implemented fully. I think that opApply with an
alias instead of a delegate would be a great thing to have, rather than
having to rely on a "sufficiently smart compiler" to inline delegates
for opApply (LDC does this sometimes, though not very reliably) or not
being able to use opApply in ultra performance-critical situations
(status quo with DMD). Is there any fundamental reason design reason
why this didn't work out, or is it just yet another low-priority todo?
/*******************************************
* Infer foreach arg types from a template function opApply which looks
like:
* int opApply(alias int func(ref uint))() { ... }
*/
#if 0
void inferApplyArgTypesZ(TemplateDeclaration *tstart, Parameters *arguments)
{
for (TemplateDeclaration *td = tstart; td; td = td->overnext)
{
if (!td->scope)
{
error("forward reference to template %s", td->toChars());
return;
}
if (!td->onemember ||
!td->onemember->toAlias()->isFuncDeclaration())
{
error("is not a function template");
return;
}
if (!td->parameters || td->parameters->dim != 1)
continue;
TemplateParameter *tp = (TemplateParameter
*)td->parameters->data[0];
TemplateAliasParameter *tap = tp->isTemplateAliasParameter();
if (!tap || !tap->specType || tap->specType->ty != Tfunction)
continue;
TypeFunction *tf = (TypeFunction *)tap->specType;
if (inferApplyArgTypesY(tf, arguments) == 0) // found it
return;
}
}
#endif
More information about the dmd-internals
mailing list