view lphobos/std/stdio.d @ 35:3cfcb944304e trunk

[svn r39] * Updated to DMD 1.022 with the exception of: Bugzilla 278: dmd.conf search path doesn't work This fix was causing crashes for me :/ So for it's the old behaviour
author lindquist
date Tue, 09 Oct 2007 06:21:30 +0200
parents 77e3d1ddae3f
children 77cdca8c210f
line wrap: on
line source

module std.stdio;

import std.traits;

void _writef(T)(T t) {
  static if(is(T: Object)) _writef(t.toString()); else
  static if(is(T==char)) printf("%c", t); else
  static if(is(T: char[])) printf("%.*s", t.length, t.ptr); else
  static if(isArray!(T)) {
    _writef('[');
    if (t.length) _writef(t[0]);
    for (int i=1; i<t.length; ++i) { _writef(','); _writef(t[i]); }
    _writef(']');
  } else
  static if(is(T==int)) printf("%i", t); else
  static assert(false, "Cannot print "~T.stringof);
}

void writef(T...)(T t) {
  foreach (v; t) _writef(v);
}
void writefln(T...)(T t) {
  writef(t, "\n"[]);
}