this is almost a workaround for the lack of named parameters
J
not_avail at notavailable.com
Thu Mar 21 11:35:23 PDT 2013
#!/usr/bin/rdmd
void main(string[] arg) {
// Observation: I'd like to say:
/*
auto r = myfunc.call("named") with { z= 2; x = -123; y = 200; }
*/
// and have it turned into this:
with(myfunc) { x = -123; y = 200; z = -20; }
auto r = myfunc.call("named");
// Q: is there some way to achieve this? Maybe a variation on
with?
// Is there a macro facility lurking someplace? Or is there
another way to do this?
// Thanks!
// - J
}
import std.stdio;
struct myfunc_
{
// named keyword or named parameters
// --the call arguments and their defaults
int x=0;
int y=0;
int z=0;
string call(string non_keyword_arg)
{
writefln("%s: X %s, Y %s, Z %s", non_keyword_arg, x, y, z );
return "yo";
}
}
myfunc_ myfunc;
More information about the Digitalmars-d
mailing list