Dicebot on leaving D: It is anarchy driven development in all its glory.
Timon Gehr
timon.gehr at gmx.ch
Fri Aug 24 20:46:53 UTC 2018
On 24.08.2018 21:42, tide wrote:
>
> Some problems require new features like how taking the address of a
> member function without an object returns a function pointer, but
> requires a delegate
That is indeed broken behavior (and I think there is a DIP to fix it),
but member function pointers are not really a necessary language feature.
> where C++ has member function pointers, D just has
> broken unusable code.
You can use a
T function(ref S, Args)
in place of a
T (S::*)(Args)
(for S a value type, otherwise you don't need the ref).
Then, instead of
auto mptr = &S::foo;
you write
auto mptr = (ref S s, Args args) => s.foo(args);
(This is a bit more typing, but it can be automated, such that you only
write getMPtr!(S.foo) or similar.)
instead of
s->*mptr(args)
you write
mptr(s, args)
The syntax is more obvious, it is more general, and at least some C++
compilers will do the same thing under the hood.
More information about the Digitalmars-d
mailing list