<div dir="ltr">On 10 June 2013 21:35, Jacob Carlborg <span dir="ltr"><<a href="mailto:doob@me.com" target="_blank">doob@me.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 2013-06-10 11:45, Manu wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
A function pointer is a pointer. A delegate is a pointer to a function<br>
and a context pointer, ie, 2 pointers.<br>
A pointer to a method is just a pointer to a function, but it's a<br>
special function which receives a 'this' argument with a special calling<br>
convention.<br>
It's definitely useful to be able to express a 'thiscall' function pointer.<br>
</blockquote>
<br></div>
It's not very useful without the context pointer, i.e. "this".<br></blockquote><div><br></div><div style>You supply 'this' at the time of calling. Read my OP.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
        Also, extern(C++) delegates are useful too in their own right<br>
<br>
<br>
    To do what? As far as I know C++ doesn't have anything corresponding<br>
    to a D delegate.<br>
<br>
<br></div><div class="im">
C++ has FastDelegate, which I use to interact with D delegates all the<br>
time! ;)<br>
</div></blockquote>
<br>
I didn't know about that. Is that something that is in the language or standard library?</blockquote><div><br></div><div style>It's Don's work of art. It's also how I came to find out about D in the first place ;)</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
extern(C++) delegate is required to specify the appropriate calling<br>
convention, otherwise it's just a delegate like usual.<br>
</blockquote>
<br></div>
I see.<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I'm just trying to show that sometimes you don't want a delegate, you<br>
just want a function pointer.<br>
</blockquote>
<br></div>
Then use a function pointer.</blockquote><div><br></div><div style>There's no way to specify to use the 'thiscall' calling convention.</div><div style>What I propose is a syntax that would describe a member function pointer, and imply the appropriate calling convention.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
delegate's contain the function pointer I'm after, so I can access it<br>
indirectly, but it's just not so useful. It's not typed (is void*), and<br>
you can't call through it.<br>
</blockquote>
<br></div>
The function pointer of a delegate is typed, it's the context pointer that is void*.<br>
<br>
Sorry, I'm just trying to understand what you're doing, what problems you have. You can compose and decompose delegates using its built-in properties "ptr" and "funcptr".<br>
<br>
You can do something like:<br>
<br>
class Foo<br>
{<br>
    int i;<br>
<br>
    void a () { writeln("Foo.a i=", i); }<br>
    void b () { writeln("Foo.b i=", i); }<br>
}<br>
<br>
void main ()<br>
{<br>
    auto f1 = new Foo;<br>
    f1.i = 3;<br>
    auto dg = &f1.a;<br>
    dg();<br>
<br>
    auto f2 = new Foo;<br>
    f2.i = 4;<br>
    dg.ptr = cast(void*) f2;<br>
    dg();<br>
<br>
    dg.funcptr = &Foo.b;<br>
    dg();<br>
}<br>
<br>
The only thing that doesn't work with the above is if I change the context pointer to a subclass of Foo which overrides the method I want to call. It will still call the method in Foo unless I change "funcptr".</blockquote>
<div><br></div><div style>I wouldn't say that doesn't work, I'd say that works perfectly. A delegate is just a 'this' and function pair. If you change 'this', there's no reason the function should change.</div>
<div style><br></div><div style>funcptr pretends to be typed, but the type is just wrong. In your example, the type is 'void function()', it should be 'void function(Foo this)'.</div><div style>So it's actually a lie. You can't call it. I'm not sure why it's typed at all... just a crash waiting to happen.</div>
<div style>So what I'm suggesting is a syntax to express a member function pointer, and then it could be properly typed.<br></div></div></div></div>