On Tuesday, 15 May 2018 at 21:25:05 UTC, Andrei Alexandrescu
wrote:
Hello, I was reviewing again DIP 1011 and investigated a
library solution. That led to
https://gist.github.com/run-dlang/18845c9df3d73e45c945feaccfebfcdc
It builds on the opening examples in:
https://github.com/dlang/DIPs/blob/master/DIPs/DIP1011.md
I'm displeased at two aspects of the implementation:
* Perfect forwarding is tedious to implement: note that
makeDelegate hardcodes void as the return type and (int, float)
as parameter types. Ideally it should accept any parameters
that the alias passes.
* Pass-by-alias and overloading interact poorly. Does anyone
know how to refer by alias to one specific overload?
Thanks,
Andrei
Now that I've had a chance to look the example you've shared, the
only comment I'd make is that DIP1011 aims to allow applications
to create "delegate-compatible" functions that don't require
generating a wrapper function to forward a delegate call to the
function at runtime In this example, 2 functions have been
defined that take a class and a struct pointer as the first
argument, however, these function are not ABI compatible with the
delegate ABI meaning you will have to generate a runtime
"conversion" function to forward a delegate call to call the
function.
extern(delegate) allows the application to generate the function
using the delegate ABI in the first place so no "conversion" is
necessary. To achieve this with a libary solution, you need to
modify the function definition itself, not just create a wrapper
around it.