digitalmars.D.learn - function default parameters lost
- Paul D Anderson (40/40) Jun 24 2015 I'm trying to pass a function pointer while keeping the default
- tcak (4/7) Jun 25 2015 I filed a bug about 2-3 months ago about default parameters
- Paul D Anderson (2/11) Jun 25 2015 Thanks
- Paul D Anderson (3/15) Jun 26 2015 Turns out this is expected behavior. Default parameter values are
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
Jun 24 2015
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.
Jun 25 2015
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:ThanksI'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.
Jun 25 2015
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:Turns out this is expected behavior. Default parameter values are stripped from function pointers.On Thursday, 25 June 2015 at 04:43:51 UTC, Paul D Anderson wrote:ThanksI'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.
Jun 26 2015