What's left for 1.0?

Bill Baxter dnewsgroup at billbaxter.com
Tue Nov 28 19:30:59 PST 2006


Bill Baxter wrote:
> Kirk McDonald wrote:
>> Bill Baxter wrote:
>>> Kirk McDonald wrote:
>>>> In writing Pyd, I've come to the conclusion that if you have a 
>>>> template that accepts an arbitrary function as an alias parameter 
>>>> (and then does anything involving the type of that function), you 
>>>> should always have a second parameter representing the type of the 
>>>> function. (And you can easily make this second parameter have a 
>>>> default value of typeof(&fn).) In this way the user can be sure the 
>>>> template is getting the proper overload of the function.
>>>
>>> If you had some extra condition like "I want to match the version 
>>> with the most arguments" can you think of some way to make that work 
>>> with the current D?
>>>
>>> --bb
>>
>> No, because there is no way to get another overload of a function 
>> beyond the first without knowing the type of the overload.
>>
> 
> Hmm, I was hoping maybe there's a way to use a series of templates like
> 
>     void set_function(Ret,A1,A2,A3)(Ret delegate(A1,A2,A3) dg) { ... }
>     void set_function(Ret,A1,A2)(Ret delegate(A1,A2) dg) { ... }
>     void set_function(Ret,A1)(Ret delegate(A1) dg) { ... }
>     void set_function(Ret)(Ret delegate() dg) { ... }
> 
> where ifti would prefer the one with more arguments to one with fewer.
> Of course if that were the solution it would take us right back into the 
> bad old days before TypeTuples.
> 
> --bb

.. And it doesn't work.  Just gives you the lexical ordering again:

import std.stdio : writefln;

void func(int a, float b)
{
     writefln("func(int, float)");
}
void func(int a)
{
     writefln("func(int)");
}
void func()
{
     writefln("func()");
}

void do_it(A1,A2)(void function(A1, A2) f) {
     f(1,2.0);
}
void do_it(A1)(void function(A1) f) {
     f(3);
}
void do_it()(void function() f) {
     f();
}

void main()
{
     // no dice, still you get the func that's lexically first
     do_it(&func);
}

Your solution of passing the parameters for the version you want to the 
template is ok, except with the way IFTI works it's a headache when 
there are other parameters that could otherwise be guessed by IFTI that 
suddenly have to be specified too.


--bb



More information about the Digitalmars-d mailing list