Feedback Thread: DIP 1032--Function pointers and Delegate Parameters...--Community Review Round 1

Piotr Mitana piotr.mitana at gmail.com
Tue Apr 7 06:57:57 UTC 2020


In some cases i may want to pass a @system delegate to a @safe 
function (or - more likely - method). The first case that comes 
into my mind is a constructor or setter.

import std;

struct C {
     void delegate() runner;

     this(void delegate() func) pure nothrow @safe @nogc {
         runner = func;
     }

     void run() {
         runner();
     }
}

void main() {
     C c = C(() { writeln("I am not pure!"); });
     c.run();
}

In this case after this DIP constructor either could not be 
marked pure etc (and it definitely is!). or could not accept this 
function pointer.

That limitation could also surface after longer period if I used 
the constructor with pure functions in general, but at some point 
I would need to pass a impure function. I would then need to 
impurify the constructor and every place I've used it so far.

That's why in my opinion either opt-in (like the suggested 
@inherit - but is it a good enough reason to introduce a new 
@attribute and possibly break a specific of UDA with this name?) 
or not at all. I think I could live without this improvement and 
either just mark them all or use a type alias.


More information about the Digitalmars-d mailing list