1.0 ?? [templates and currying]

Kirk McDonald kirklin.mcdonald at gmail.com
Mon Nov 6 20:52:30 PST 2006


Walter Bright wrote:
> Kirk McDonald wrote:
>> This would be great! The one thing we lose is the ability to get the 
>> underlying function type of a delegate.
> 
> Is that needed, though?

Yes. It will be less needed if, as Tom suggests, there is a way to 
derive a tuple from a function or delegate type, and then derive a 
function or delegate type from a tuple.

As was pointed out in a previous thread, the latter could be done if the 
following worked:

template FuncType(Ret, T ...) {
     alias Ret function(T) FuncType;
}

In Pyd, users wrap member functions by providing an alias to the member 
function directly. Take the following class:

class Foo {
     void f() { }
}

Wrapping this class in Pyd might be done with:

wrapped_class!(Foo) f;
f.def!(Foo.f);
finalize_class(f);

The signature of .def is:

void def(alias fn, char[] name=symbolnameof!(fn), fn_t=typeof(&fn))();

fn_t, then, comes out to be void function(). Note that this is a 
/function/ type, and not a delegate type (which is right and proper). To 
actually call this, I need to derive a delegate type from this function 
type, and perform some hackery to call it.

Which brings up another point: It's really great that you added the .ptr 
property to delegates in 0.168, but it would also be great to have a .fn 
property to access the function pointer. (And optimally, this pointer 
would be of the right type, and not just a void*.)

-- 
Kirk McDonald
Pyd: Wrapping Python with D
http://pyd.dsource.org



More information about the Digitalmars-d mailing list