S
Stewart Gordon
Using g++ 3.1, Mac OS X.
I'm doing something trying to involve a null output stream, i.e. a
stream that just discards what goes into it.
The idea is that it gives a simple way of producing debugging output,
which can be controlled at runtime. For example:
Debug(5) << "Doing something..." << endl;
would output iff the debug level is at least 5. If the level is less
than 5, Debug(5) would need to evaluate to some kind of null stream.
Meanwhile I've solved it by having Debug(int) return a wrapper object,
which has operator << overloaded.
template <class T>
const DebugStream& operator<< (const DebugStream& ds, const T& t) {
if (ds.Show) std::clog << t;
return ds;
}
However, this doesn't like manipulators for some reason.
I suppose I could go platform-specific by opening /dev/null for output
and using that instead of the makeshift DebugStream class.
But does anyone know of a better solution?
Stewart.
I'm doing something trying to involve a null output stream, i.e. a
stream that just discards what goes into it.
The idea is that it gives a simple way of producing debugging output,
which can be controlled at runtime. For example:
Debug(5) << "Doing something..." << endl;
would output iff the debug level is at least 5. If the level is less
than 5, Debug(5) would need to evaluate to some kind of null stream.
Meanwhile I've solved it by having Debug(int) return a wrapper object,
which has operator << overloaded.
template <class T>
const DebugStream& operator<< (const DebugStream& ds, const T& t) {
if (ds.Show) std::clog << t;
return ds;
}
However, this doesn't like manipulators for some reason.
I suppose I could go platform-specific by opening /dev/null for output
and using that instead of the makeshift DebugStream class.
But does anyone know of a better solution?
Stewart.