June 10, 2013 Re: Member function pointers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | On 2013-06-10 15:47, Manu wrote: > I'm really not asking for delegates (although they could become more > typesafe given my suggestion), just a member function pointer. And not > C++ style as you say, my suggestion is much simpler than that, and would > fit nicely in D. I give up, I don't understand what you want. -- /Jacob Carlborg |
June 10, 2013 Re: Member function pointers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg Attachments:
| On 11 June 2013 00:43, Jacob Carlborg <doob@me.com> wrote:
> On 2013-06-10 15:47, Manu wrote:
>
> I'm really not asking for delegates (although they could become more
>> typesafe given my suggestion), just a member function pointer. And not C++ style as you say, my suggestion is much simpler than that, and would fit nicely in D.
>>
>
> I give up, I don't understand what you want.
...a member function pointer syntax. It's not that complex.
My suggestion is: void function(T this) funcptr;
This is a function pointer (not a delegate), but using keyword 'this' gives
the critical detail to the compiler that it's a member function pointer,
and to use the appropriate calling convention when making calls through
this pointer.
UFCS makes it awesome.
|
June 10, 2013 Re: Member function pointers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On Monday, 10 June 2013 at 14:43:50 UTC, Jacob Carlborg wrote:
> On 2013-06-10 15:47, Manu wrote:
>
>> I'm really not asking for delegates (although they could become more
>> typesafe given my suggestion), just a member function pointer. And not
>> C++ style as you say, my suggestion is much simpler than that, and would
>> fit nicely in D.
>
> I give up, I don't understand what you want.
Let me try to summarize it in code:
---
class A { void foo(); }
auto memberFun = (&A.foo).funcptr;
auto a = new A;
memberFun(a);
---
David
|
June 10, 2013 Re: Member function pointers | ||||
---|---|---|---|---|
| ||||
Posted in reply to David Nadlinger | On 2013-06-10 17:40, David Nadlinger wrote: > Let me try to summarize it in code: > > --- > class A { void foo(); } > auto memberFun = (&A.foo).funcptr; > > auto a = new A; > memberFun(a); > --- Why is this better than a delegate? -- /Jacob Carlborg |
June 10, 2013 Re: Member function pointers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | On 2013-06-10 17:36, Manu wrote: > My suggestion is: void function(T this) funcptr; > This is a function pointer (not a delegate), but using keyword 'this' > gives the critical detail to the compiler that it's a member function > pointer, and to use the appropriate calling convention when making calls > through this pointer. > UFCS makes it awesome. What I don't understand is what this give you that a delegate doesn't. You need the "this" pointer to call the function pointer anyway. With a delegate it's bundled. -- /Jacob Carlborg |
June 10, 2013 Re: Member function pointers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg Attachments:
| On 11 June 2013 02:26, Jacob Carlborg <doob@me.com> wrote:
> On 2013-06-10 17:40, David Nadlinger wrote:
>
> Let me try to summarize it in code:
>>
>> ---
>> class A { void foo(); }
>> auto memberFun = (&A.foo).funcptr;
>>
>> auto a = new A;
>> memberFun(a);
>> ---
>>
>
> Why is this better than a delegate?
It's not 'better', it's different.
|
June 10, 2013 Re: Member function pointers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | Am 10.06.2013 18:28, schrieb Jacob Carlborg:
> On 2013-06-10 17:36, Manu wrote:
>
>> My suggestion is: void function(T this) funcptr;
>> This is a function pointer (not a delegate), but using keyword 'this'
>> gives the critical detail to the compiler that it's a member function
>> pointer, and to use the appropriate calling convention when making calls
>> through this pointer.
>> UFCS makes it awesome.
>
> What I don't understand is what this give you that a delegate doesn't.
> You need the "this" pointer to call the function pointer anyway. With a
> delegate it's bundled.
>
maybe he just don't need one to handle the this ptr because he wants to call several/hundrets of member-functions?
|
June 10, 2013 Re: Member function pointers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | On 2013-06-10 18:34, Manu wrote: > On 11 June 2013 02:26, Jacob Carlborg <doob@me.com <mailto:doob@me.com>> > wrote: > > On 2013-06-10 17:40, David Nadlinger wrote: > > Let me try to summarize it in code: > > --- > class A { void foo(); } > auto memberFun = (&A.foo).funcptr; > > auto a = new A; > memberFun(a); > --- > > > Why is this better than a delegate? > > > It's not 'better', it's different. class A { void foo(); } auto memberFun = (&A.foo).funcptr; auto a = new A; void delegate () dg; dg.funcptr = memberFun; dg.ptr = cast(void*) a; dg(); The details can be hidden in a function call. Sure, a delegate could be type safe but still don't see the point. -- /Jacob Carlborg |
June 10, 2013 Re: Member function pointers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg Attachments:
| On 11 June 2013 02:28, Jacob Carlborg <doob@me.com> wrote:
> On 2013-06-10 17:36, Manu wrote:
>
> My suggestion is: void function(T this) funcptr;
>> This is a function pointer (not a delegate), but using keyword 'this'
>> gives the critical detail to the compiler that it's a member function
>> pointer, and to use the appropriate calling convention when making calls
>> through this pointer.
>> UFCS makes it awesome.
>>
>
> What I don't understand is what this give you that a delegate doesn't. You need the "this" pointer to call the function pointer anyway. With a delegate it's bundled.
It's just a pointer, 'this' is associated at the call site. And it's
strongly typed.
If you don't want a bundle, why be forced to use a bundled type?
Consider this, why would you ever want an int* when you can have an int[]?
We could remove the syntax for int*, and make it only accessible via
int[].ptr... and make: is(typeof(int[].ptr) == size_t)? :)
|
June 10, 2013 Re: Member function pointers | ||||
---|---|---|---|---|
| ||||
Posted in reply to dennis luehring | On 2013-06-10 18:38, dennis luehring wrote: > maybe he just don't need one to handle the this ptr because he wants to > call several/hundrets of member-functions? How does he call a pointer to a member function without the "this" pointer? -- /Jacob Carlborg |
Copyright © 1999-2021 by the D Language Foundation