function default parameters lost
Paul D Anderson via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jun 24 21:43:50 PDT 2015
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
More information about the Digitalmars-d-learn
mailing list