Skip to content

Instantly share code, notes, and snippets.

@zaydek-old
Created August 3, 2017 11:49
Show Gist options
  • Save zaydek-old/6575442a74927c280349abb2bbd37a87 to your computer and use it in GitHub Desktop.
Save zaydek-old/6575442a74927c280349abb2bbd37a87 to your computer and use it in GitHub Desktop.
import std.stdio, core.stdc.stdlib;
void main()
{
}
/+
cache
+/
static struct cache
{
static File file;
/+
opCall
+/
static opCall(T...)(T args) if (!is(typeof(args[0]) == File))
{
if (!file.isOpen)
file = stdout;
return file == stdout || file == stderr ? opCall!(true)(file, args) : opCall(file, args);
}
/+
opCall
+/
static opCall(bool std = false, T...)(File file, T args)
{
static if (!is(typeof(args[0]) == string))
file.writeln (args);
else
file.writefln(args);
if (file != stdout && file != stderr)
file.flush();
static if (!std) { writeln("hello"); file.flush(); }
return (ubyte code = 1) => exit(code);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment