[dmd-internals] opApply with alias instead of delegate?
Walter Bright
walter at digitalmars.com
Sun Jan 9 12:23:08 PST 2011
I wrote that a very long time ago, and don't remember the details.
David Simcha wrote:
> 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
>
> _______________________________________________
> dmd-internals mailing list
> dmd-internals at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/dmd-internals
>
>
More information about the dmd-internals
mailing list