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

Dennis dkorpel at gmail.com
Thu Jul 30 10:18:58 UTC 2020


On Thursday, 30 July 2020 at 03:16:02 UTC, Walter Bright wrote:
> On 7/29/2020 4:26 AM, Dennis wrote:
>> How would you solve this if you were the library author?
>
> The usual way is with templates.

That will not work here, opApply is a virtual function.

It also breaks in cases where the parameter type is not specified:

```
new Tree().opApply(x => 0); // works with delegate
// with template: opApply cannot deduce function from argument 
types !()(void)
```

This is not a hypothetical situation, I had to deal with this 
when making std.bigint @safe, because a project on buildkite 
broke.
https://github.com/dlang/phobos/blob/f5197c82e7b0d1fad2f37233a72f46a56f3f17eb/std/bigint.d#L1330

Then there's other scenarios where you can't use templates:
- Library is compiled as a shared lib
- Library is closed source
- Library has extern(System) interface (e.g. 
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-enumdisplaymonitors)



More information about the Digitalmars-d mailing list