Created
July 21, 2012 07:56
-
-
Save 4poc/3155033 to your computer and use it in GitHub Desktop.
C++11 variadic template printf with boost::format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <boost/format.hpp> | |
void LogMessage(boost::format& message) { | |
std::cout << message.str() << std::endl; | |
} | |
template<typename TValue, typename... TArgs> | |
void LogMessage(boost::format& message, TValue arg, TArgs... args) { | |
message % arg; | |
LogMessage(message, args...); | |
} | |
template<typename... TArgs> | |
void LogMessage(std::string fmt, TArgs... args) { | |
boost::format message(fmt); | |
LogMessage(message, args...); | |
} | |
int main() { | |
LogMessage("a%d b%d", 0, 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment