From 13a87ff8ca3d2ef0a8766b0d0e56e537cc0ed697 Mon Sep 17 00:00:00 2001 From: Denis Shelomovskij Date: Tue, 11 Sep 2012 20:31:05 +0400 Subject: [PATCH] Improve std.stdio.File.{writef,writefln} * don't throw AssertError in writef * make these functions consistent with std.format.formattedWrite --- std/stdio.d | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/std/stdio.d b/std/stdio.d index 8fadf08ab..fa3de01a5 100644 --- a/std/stdio.d +++ b/std/stdio.d @@ -720,33 +720,21 @@ arguments in text format to the file, followed by a newline. */ write(args, '\n'); } - private enum errorMessage = - "You must pass a formatting string as the first" - " argument to writef or writefln. If no formatting is needed," - " you may want to use write or writeln."; - /** If the file is not opened, throws an exception. Otherwise, writes its arguments in text format to the file, according to the format in the first argument. */ - void writef(S...)(S args) // if (isSomeString!(S[0])) + void writef(Char, A...)(in Char[] fmt, A args) { - assert(_p); - assert(_p.handle); - static assert(S.length>0, errorMessage); - static assert(isSomeString!(S[0]) && !is(S[0] == enum), errorMessage); - auto w = lockingTextWriter; - std.format.formattedWrite(w, args); + std.format.formattedWrite(lockingTextWriter, fmt, args); } /** Same as writef, plus adds a newline. */ - void writefln(S...)(S args) + void writefln(Char, A...)(in Char[] fmt, A args) { - static assert(S.length>0, errorMessage); - static assert(isSomeString!(S[0]) && !is(S[0] == enum), errorMessage); auto w = lockingTextWriter; - std.format.formattedWrite(w, args); + std.format.formattedWrite(w, fmt, args); w.put('\n'); }