I am writing a logger. If disabled, this is the code which defines the LOG macro:
#ifdef NO_LOG
#include <ostream>
struct nullstream : std::ostream {
nullstream() : std::ios(0), std::ostream(0) {}
};
static nullstream logstream;
#define LOG if(0) logstream
#endif
LOG << "Log message " << 123 << std::endl;
It works correctly. The compiler should completely remove the code related to the LOG macro.
However I would like to avoid the inclusion of ostream and define the logstream object as something really "light", possibly null.
Thank you!