Parameterized delegate attributes

Eyal Lotem via Digitalmars-d digitalmars-d at puremagic.com
Wed Sep 28 09:20:18 PDT 2016


struct Example {
     int opApply(int delegate(int x) dlg) const {
         return dlg(0);
     }
}

Example.opApply now cannot be used in a @nogc context, even 
though it is fully @nogc whenever dlg is.

Ditto with nothrow, pure, @safe and other attributes.

For a large code-base containing higher-order functions, this 
makes use of these attributes nearly impractical.

What I would like to say is something like:

struct Example {
     int opApply(int delegate(int x) dlg G?@nogc T?nothrow P?pure) 
const @G @T @P {
         return dlg(0);
     }
}

The above would assign G to @nogc or nothing, according to 
whether the delegate is.
Ditto with T and nothrow, P and pure.

Then they can be used freely in other parts of the type signature.

Unlike templates, these would not require any generated code 
duplication (they're just for type-checking, after all).

Fixing this along-side the more minor issue of many standard 
libraries lacking proper annotations -- would make @nogc, pure 
and nothrow much more practical.


More information about the Digitalmars-d mailing list