Key arguments
Jarrett Billingsley
kb3ctd2 at yahoo.com
Mon Jul 14 06:17:17 PDT 2008
"baleog" <maccarka at yahoo.com> wrote in message
news:g5er1d$1p15$1 at digitalmars.com...
> How can i implement key arguments in D? I want something like this:
> --
> void f(int x, double y = 2.0, int z = 3);
> ...
> f(1, z:10, y:5.1); // x=1, y=5.1, z=10
> f(1, z:10); // x=1, y=2.0, z=10
> --
> I tried to do this with Variant type and explicit type checking. But it
> takes a lot of routine actions. Maybe exists a better way?
>
> Best regards
Downs will reply with a horrid hack involving overloading opAssign for some
static instances of some structures and then getting their values in the
function, but then you're severely limited since the "parameter" names are
globals, and since that's so, you can't have two functions that use the same
named parameters executing at the same time, either in a multithreaded
fashion or with simple recursion.
There's no general purpose way to do it, no.
More information about the Digitalmars-d-learn
mailing list