grauzone wrote:
Andrei Alexandrescu wrote:
You mean use a struct for the string-value pair? A struct cannot have a ref member, so it would still need to store a pointer. (But maybe I misunderstood the point.)

Like this:

void main(string[] commandline) {
    struct Args {
        string param1 = "can even have default arguments";
        int param2;
    }
    Args args = getopt!(Args)(commandline);
    writefln("param1 = %s", args.param1);
}

No pointers. Instead of returning it, struct could be passed by ref, too.

I think that's a good idea, but we still need a means to express the name of the parameters e.g. for mapping "--multi-word-option" to multiWordOption. Then I fear things will inevitably get thicker, and simplicity was the main attractiveness of getopt.

(FWIW, getopt is somewhat dear to me; it was one of the first pieces of code I wrote in D. I'd dreamed for such a simple facility for years, and I was very glad that it was doable in D. If getopt starts becoming bigger and more nontrivial to use, I think some of the elegance of its initial design would be lost.)


Andrei

Reply via email to