Thread overview | ||||||
---|---|---|---|---|---|---|
|
June 25, 2015 function default parameters lost | ||||
---|---|---|---|---|
| ||||
I'm trying to pass a function pointer while keeping the default parameter values intact. Given the following: import std.traits; import std.stdio; int foo(int a, int b = 1) { return a; } alias FOOP = int function(int, int = 1); struct ST(POOF) { FOOP fctn; this(POOF fctn) { this.fctn = fctn; } void details() { alias PDVA = ParameterDefaultValueTuple!fctn; writefln("typeid(PDVA[0]) = %s", typeid(PDVA[0])); writefln("typeid(PDVA[1]) = %s", typeid(PDVA[1])); } } void main() { FOOP fp = &foo; auto st = ST!FOOP(fp); st.details; } The default parameter value types are void, int: a has no default and b has an int value as its default. If I change line 14 from FOOP fctn; to POOF fctn; The default parameter value types are void, void. In other words the default value for b is no longer there. Why doesn't invoking the template (ST!FOOP) replace POOF in line 14 with FOOP? Paul |
June 25, 2015 Re: function default parameters lost | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paul D Anderson | On Thursday, 25 June 2015 at 04:43:51 UTC, Paul D Anderson wrote:
> I'm trying to pass a function pointer while keeping the default parameter values intact. Given the following:
>
> [...]
I filed a bug about 2-3 months ago about default parameters similar to yours. My guess is that it hasn't been fixed yet, and you have hit the same issue.
|
June 25, 2015 Re: function default parameters lost | ||||
---|---|---|---|---|
| ||||
Posted in reply to tcak | On Thursday, 25 June 2015 at 07:10:57 UTC, tcak wrote:
> On Thursday, 25 June 2015 at 04:43:51 UTC, Paul D Anderson wrote:
>> I'm trying to pass a function pointer while keeping the default parameter values intact. Given the following:
>>
>> [...]
>
> I filed a bug about 2-3 months ago about default parameters similar to yours. My guess is that it hasn't been fixed yet, and you have hit the same issue.
Thanks
|
June 26, 2015 Re: function default parameters lost | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paul D Anderson | On Thursday, 25 June 2015 at 14:17:13 UTC, Paul D Anderson wrote:
> On Thursday, 25 June 2015 at 07:10:57 UTC, tcak wrote:
>> On Thursday, 25 June 2015 at 04:43:51 UTC, Paul D Anderson wrote:
>>> I'm trying to pass a function pointer while keeping the default parameter values intact. Given the following:
>>>
>>> [...]
>>
>> I filed a bug about 2-3 months ago about default parameters similar to yours. My guess is that it hasn't been fixed yet, and you have hit the same issue.
>
>
> Thanks
Turns out this is expected behavior. Default parameter values are stripped from function pointers.
|
Copyright © 1999-2021 by the D Language Foundation