Function pointers/delegates default args were stealth removed?

Timon Gehr timon.gehr at gmx.ch
Sun Aug 26 18:55:35 PDT 2012


On 08/27/2012 02:44 AM, Walter Bright wrote:
> On 8/26/2012 4:50 PM, Timon Gehr wrote:
>> On 08/27/2012 12:41 AM, Walter Bright wrote:
>>>
>>> The trouble for function pointers, is that any default args would need
>>> to be part of the type, not the declaration.
>>>
>>
>> They could be made part of the variable declaration.
>
> You mean part of the function pointer variable?
>

Yes.

> Consider what you do with a function pointer - you pass it to someone
> else. That someone else gets it as a type, not a declaration.

If it is a template function, yes. But then you may as well pass the
function pointer variable per alias, which is common.

Otherwise someone else gets nothing but a parameter declaration.

> I.e. you lose the default argument information, since that is not attached to the
> type.
>

I think most valid existing use cases would still be supported:

int execFunctionPointer(int function(int = 2) fun){
     return fun();
}

auto dg = (int x, int y=2){ return x+y; }
writeln(range.map!dg());

int function(int=3)[] funs;
funs[0]();

It is up to you if it is worth the effort, of course.


More information about the Digitalmars-d mailing list