view lphobos/std/stdio.d @ 73:b706170e24a9 trunk

[svn r77] Fixed foreach on slice. Fixed some nested function problems when accessing outer function parameters. Major changes to handling of structs. Initial support for unions. Probably more...
author lindquist
date Wed, 31 Oct 2007 03:11:32 +0100
parents 2c3cd3596187
children 61615fa85940
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 if(is(T: real)) printf("%f", 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");
}