determine parameter storage class in D 2.0

Christian Kamm kamm.incasoftware at shift-at-left-and-remove-this.de
Sun Feb 3 10:59:36 PST 2008


Has someone figured out a reliable way to determine at compile time whether
a function parameter is passed by reference or by copy?

The functionality (ParamsPassMethodTuple) in std.bind does not work. (It
expects that giving a const T to a function expecting ref T will fail,
which leads to wrong results for simple types like int.) 

Modifying it to check with enum T, invariant T or the type's initializer
fails. I noticed that ParameterTypeTuple!(function) contains the ref/out
etc. in the tuple, but there seems to be no way to test for it. (stringof
aside)

Anyway, I think it's odd that for

void foo(ref int i) {}
void foo2(ParameterTypeTuple!(foo)) {}

ParameterTypeTuple!(foo) is (ref int) and
ParameterTypeTuple!(foo2) is (int).

Regards,
Christian Kamm


More information about the Digitalmars-d-learn mailing list