http://d.puremagic.com/issues/show_bug.cgi?id=8687
Andrej Mitrovic <andrej.mitrov...@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |k.hara...@gmail.com --- Comment #1 from Andrej Mitrovic <andrej.mitrov...@gmail.com> 2013-06-22 00:22:18 PDT --- A better use-case is: void foo(Args...)(Args args, string file = __FILE__, size_t line = __LINE__) { } This would allow us to construct error messages with file + line but without creating template bloat because file and line usually have to become template value arguments in order to support variadic arguments. IOW the above currently has to be: void foo(string file = __FILE__, size_t line = __LINE__, Args...)(Args args) { } But this creates too much template bloat. I've seen other people ask for this feature, I think schveiguy (Steven Schveighoffer) mentioned it as well. Here's an example use-case, where an enforce-style function can take a format string and avoid the need to call format() explicitly from the call-site: /** Similar to $(D enforce), except it can take a formatting string as the second argument. */ T require(T, Args...) (T value, lazy Args args, string file = __FILE__, size_t line = __LINE__) { static if (Args.length) string msg = Args.length > 1 ? format(args[0], args[1 .. $]) : text(args); else enum msg = "requirement failed."; if (!value) throw new Exception(msg, file, line); return value; } unittest { string file = "foo.d"; require(file.exists, "File '%s' does not exist.", file); } Currently this won't compile unless you make file and line compile-time arguments. @Kenji: Do you think it's possible to implement this without a big disruption (e.g. code breakage)? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------