What's left for 1.0?

Bill Baxter dnewsgroup at billbaxter.com
Tue Nov 28 17:38:54 PST 2006


Kirk McDonald wrote:
> Bill Baxter wrote:
>> BCS wrote:
>>> There is no way to differentiate between function overloads.
>>>
>>>
>>> int foo(){ return 0;}
>>> int foo(int i){ return 0;}
>>>
>>>
>>> int bob()
>>> {
>>>         // foo() or foo(int)?
>>>     auto fn = &foo;
>>>     auto tmp = TemplateTakingFn!(foo);
>>> }
>>
>> That should probably be an "error: ambiguous" if it isn't already, but 
>> anyway can't you do   'int function() fn = &foo' to get the one you want?
>>
>> --bb
> 
> I've played with just about every permutation of this problem during the 
> course of writing Pyd.
> 
> int foo() { return 0; }
> int foo(int i) { return 0; }
> 
> void main() {
>     auto fn = &foo; // Uses the lexically first function
>     static assert(is(typeof(fn) == int function()));
>     fn();
>     //fn(12); // Error: expected 0 arguments, not 1
>     int function(int) fn2 = &foo; // Works
>     fn2(12);
> }
> 
> 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



More information about the Digitalmars-d mailing list