Mercurial > projects > ldc
annotate lphobos/std/stdio.d @ 23:77e3d1ddae3f trunk
[svn r27] * Fixed bug in aggregate field lookup.
* Fixed structs with no fields.
* Added support for NegExp as in -x.
author | lindquist |
---|---|
date | Thu, 04 Oct 2007 09:24:15 +0200 |
parents | a6360e68134a |
children | 77cdca8c210f |
rev | line source |
---|---|
18 | 1 module std.stdio; |
2 | |
22
a6360e68134a
[svn r26] * Fixed templates defining a constant value
lindquist
parents:
21
diff
changeset
|
3 import std.traits; |
a6360e68134a
[svn r26] * Fixed templates defining a constant value
lindquist
parents:
21
diff
changeset
|
4 |
18 | 5 void _writef(T)(T t) { |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
6 static if(is(T: Object)) _writef(t.toString()); else |
22
a6360e68134a
[svn r26] * Fixed templates defining a constant value
lindquist
parents:
21
diff
changeset
|
7 static if(is(T==char)) printf("%c", t); else |
18 | 8 static if(is(T: char[])) printf("%.*s", t.length, t.ptr); else |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
9 static if(isArray!(T)) { |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
10 _writef('['); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
11 if (t.length) _writef(t[0]); |
23 | 12 for (int i=1; i<t.length; ++i) { _writef(','); _writef(t[i]); } |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
13 _writef(']'); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
14 } else |
18 | 15 static if(is(T==int)) printf("%i", t); else |
16 static assert(false, "Cannot print "~T.stringof); | |
17 } | |
18 | |
19 void writef(T...)(T t) { | |
20 foreach (v; t) _writef(v); | |
21 } | |
22 void writefln(T...)(T t) { | |
23 writef(t, "\n"[]); | |
24 } |