Andrei Alexandrescu napisał: >> Speaking of getopt, when writing the 'grep' snippet I missed anonymous >> options a lot: >> >> bool h, i; string expr; string[] files; >> getopt(args, "h",&h, "i",&i,&expr,&files); >> >> They can be implemented with relatively little effort. > > Not getting the example. How would anonymous options work?
// Let's match assignments. auto args = ["program.exe", ".*=.*;", "file1.d", "file2.d", "file3.d"]; bool h, i; string expr; string[] files; getopt(args, "h",&h, "i",&i, &expr, &files); assert(!h); assert(!i); assert(expr == ".*=.*;"); assert(files == ["file1.d", "file2.d", "file3.d"]); assert(args == ["program.exe"]); Staying conservative, anonymous options would only be allowed at the end of the option list, because their order matters (unlike named options). Perhaps this can be relaxed with time. -- Tomek
