Mercurial > projects > ldc
annotate lphobos/std/stdio.d @ 58:2c3cd3596187 trunk
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
Added initial support for CatExp aka 'a ~ b'
Fixed global constant static arrays initialized with string literals
Fixed casting any dynamic array to void*
Fixed new expression with temporary storage
Fixed alias declarations in function scope
Fixed relational comparisons of pointers
author | lindquist |
---|---|
date | Thu, 25 Oct 2007 09:02:55 +0200 |
parents | 77cdca8c210f |
children | 61615fa85940 |
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 |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
23
diff
changeset
|
15 static if(is(T: int)) printf("%i", t); else |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
23
diff
changeset
|
16 static if(is(T: real)) printf("%f", t); else |
18 | 17 static assert(false, "Cannot print "~T.stringof); |
18 } | |
19 | |
20 void writef(T...)(T t) { | |
21 foreach (v; t) _writef(v); | |
22 } | |
23 void writefln(T...)(T t) { | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
23
diff
changeset
|
24 writef(t, "\n"); |
18 | 25 } |