import std.c.stdio; import std.string; template toData(T) { void[] toData(T t) { union u { T value; void[] data; } u uu; uu.value = t; return uu.data; } } template fromData(T) { T fromData(void[] d) { union u { T value; void[] data; } u uu; uu.data = d; return uu.value; } } void print(char[] format, void[][] data) { int idx; char c; char[] text; for (int i; i < format.length; i++) { c = format[i]; if (c != '%') { text ~= c; continue; } c = format[++i]; switch (c) { case '%': text ~= '%'; break; case '#': text ~= toString(data.length); break; case 'd': text ~= toString(fromData!(int)(data[idx++])); break; case 's': text ~= fromData!(char[])(data[idx++]); break; } } foreach (char c; text) { putchar(c); } } void main() { void[][] data; data ~= toData!(int)(123); data ~= toData!(char[])(\" "hello" \"); print(" This should be 123: %d This should be \"hello\": %s This should be three percent signs: %%%%%% This should be 2: %# ", data); }