Skip to content

Instantly share code, notes, and snippets.

@4poc
Created July 21, 2012 07:56
Show Gist options
  • Save 4poc/3155033 to your computer and use it in GitHub Desktop.
Save 4poc/3155033 to your computer and use it in GitHub Desktop.
C++11 variadic template printf with boost::format
#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