module coprint;

private import std.stdio  ;
private import std.stream ;
private import std.string ;

void coprint (File file, ...) {
  char[] string ;

  void putc (dchar c) {
    string ~= c;
  }

  std.format.doFormat(&putc, _arguments, _argptr);

  writef(`%s`c, string);
  file.writeString(string);
}

void coprintln (File file, ...) {
  char[] string ;

  void putc (dchar c) {
    string ~= c;
  }

  std.format.doFormat(&putc, _arguments, _argptr);

  writefln(`%s`c, string);
  file.writeLine(string);
}

void main () {
  auto file = new File("coprint.txt", FileMode.OutNew);

  coprintln(file, "This is some random text.");
  coprintln(file, "%d + %d = %d", 1, 2, 1 + 2);
  coprint(file, "This is printed without a new line... ");
  coprint(file, "%d - %d = %d", 3, 2, 3 - 2);
  coprintln(file, " <append new line>");

  // now to get an error
  coprintln(file, "The following is not formattable this way: %o", 3.14L);

  file.close();
}