If std.stream is going to stay around much longer (not necessarily recommended), a simple but useful enhancement would be to include a dummy output stream, similar to /dev/null. This would be useful when a function or block of code expects an output stream, and you want to simply dispose of the output.
If std.stream is going to be deprecated in the foreseeable future, then whatever replaces it should have this feature.
Comment #1 by dsimcha — 2009-09-22T11:44:14Z
This should do the job. I tested that it compiles, and it's pretty hard to have a logic error given that it's supposed to do nothing. Just to make it explicit, I hereby release the DummyStream class into the public domain, if it's even copyrightable.
/**A dummy stream for disposing of output. Supports the interface of an
* OutputStream, simply does nothing for any method call.*/
class DummyStream : OutputStream {
this() {}
void writeExact(const void* buffer, size_t size){}
size_t write(const(ubyte)[] buffer) { return buffer.length; }
void write(byte x) {}
void write(ubyte x) {}
void write(short x) {}
void write(ushort x) {}
void write(int x) {}
void write(uint x) {}
void write(long x) {}
void write(ulong x) {}
void write(float x) {}
void write(double x) {}
void write(real x) {}
void write(ifloat x) {}
void write(idouble x) {}
void write(ireal x) {}
void write(cfloat x) {}
void write(cdouble x) {}
void write(creal x) {}
void write(char x) {}
void write(wchar x) {}
void write(dchar x) {}
void write(char[] s) {}
void write(const(wchar)[] s) {}
void writeLine(const(char)[] s) {}
void writeLineW(const(wchar)[] s) {}
void writeString(const(char)[] s) {}
void writeStringW(const(wchar)[] s) {}
size_t vprintf(char[] format, va_list args) { return 0; }
size_t printf(char[] format, ...) { return 0; }
OutputStream writef(...) { return this;}
OutputStream writefln(...) { return this; }
OutputStream writefx(TypeInfo[] arguments, void* argptr, int newline = false) {
return this;
}
void flush() {}
void close() {}
bool isOpen() { return true; }
}
Comment #2 by andrei — 2009-09-22T12:12:40Z
Thanks! The patch pretty much shows the age of the stream design...
Comment #3 by shro8822 — 2009-09-22T12:40:52Z
(In reply to comment #1)
> size_t vprintf(char[] format, va_list args) { return 0; }
> size_t printf(char[] format, ...) { return 0; }
I'd think this should return the same as the function in the other classes do.
Comment #4 by dsimcha — 2009-09-22T13:08:50Z
(In reply to comment #3)
> (In reply to comment #1)
> > size_t vprintf(char[] format, va_list args) { return 0; }
> > size_t printf(char[] format, ...) { return 0; }
>
> I'd think this should return the same as the function in the other classes do.
I agree in principle, except that then you would have to do the whole formatting just to figure out what that number should be. This seems wasteful. I consider it to be a minor detail anyhow, since really, who the heck still uses vprintf and printf?
Comment #5 by dfj1esp02 — 2009-09-25T06:05:16Z
Hack.
size_t vprintf(char[] format, va_list args) { return format.length; }
size_t printf(char[] format, ...) { return format.length; }
Comment #6 by dsimcha — 2010-06-17T18:23:05Z
I'm resolving this as WONTFIX because we've decided std.stream is going the way of the dodo.