[Issue 18172] std.getopt should allow taking parameters by `ref` (like std.format.formattedRead), s.t. it can be used in @safe

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Mar 14 18:35:46 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=18172

--- Comment #2 from Jack Stouffer <jack at jackstouffer.com> ---
Actually the problem is way worse. Consider

========
string file1 = "file.dat";
string file2 = "file2.dat";

getopt(args, "file1", "info about arg", file1,
    "file2", file2);
========

It's actually, not practically, impossible to know if the string at the third
arg is to be written to or is to be used as the help info. All of the arguments
look like identical strings to the code.

One possible fix is to use tuples to break the arguments into groups

=======
string file1;
string file2;

getopt(
    args,
    tuple("arg1", "info about arg", file1),
    tuple("arg2", file2)
);
=======

--


More information about the Digitalmars-d-bugs mailing list