On 10 June 2013 18:04, Jacob Carlborg <doob@me.com> wrote:
On 2013-06-10 09:23, Manu wrote:

That seems pretty awkward to me. Basically a hack.
A function pointer is not a delegate, so I don't see why that should be
used to describe one.

It depends on how you look at it. In D a delegate is a function pointer with a context pointer. In C++ a pointer to a member function is basically the same, the context pointer is just passed separately.

A function pointer is a pointer. A delegate is a pointer to a function and a context pointer, ie, 2 pointers.
A pointer to a method is just a pointer to a function, but it's a special function which receives a 'this' argument with a special calling convention.
It's definitely useful to be able to express a 'thiscall' function pointer.

Also, extern(C++) delegates are useful too in their own right

To do what? As far as I know C++ doesn't have anything corresponding to a D delegate.

C++ has FastDelegate, which I use to interact with D delegates all the time! ;)
extern(C++) delegate is required to specify the appropriate calling convention, otherwise it's just a delegate like usual.

I haven't needed to yet... but that doesn't mean it might not be useful.
It would probably be used in D for tight binding with other systems.
AngelScript binds to native code with member function pointers... just
off the top of my head.

Actually I don't see why you can't use a delegate for this. The only difference is that it won't be virtual.

I'm just trying to show that sometimes you don't want a delegate, you just want a function pointer.
delegate's contain the function pointer I'm after, so I can access it indirectly, but it's just not so useful. It's not typed (is void*), and you can't call through it.