I'm making a logger class for my app in C++. This class has static members to log debug output to file. I would like to create a Macro that can be used in two ways:
LOG("Log some text")
which calls Logger::log(std::string)
-----or-----
LOG << "Log some text" << std::endl;
which calls Logger::getLogStream()
The goal being that including Logger.h be enough to log to file, and that it be done using the same syntax, but I'm not particularly attached to Macros if you have other suggestions. Using Boost::PP is, unfortunately, not an option.
I've looked around (see this comment), but found nothing concerning differentiating between a call to LOG and LOG(). How can I differentiate one argument from no arguments?
LOG(X)
and an object namedLOG
. The formLOG
without parentheses is not affected by the expansion of the function-like macro. It is also possible to define a function object that overloads bothoperator()
andoperator<<
. – dyp