Skip to content

Instantly share code, notes, and snippets.

@cjameshuff
Last active January 26, 2017 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjameshuff/18646f6a6755a09c7bdbd552b10f4d52 to your computer and use it in GitHub Desktop.
Save cjameshuff/18646f6a6755a09c7bdbd552b10f4d52 to your computer and use it in GitHub Desktop.
boost::format with type-safe C-style format strings
#include "boost/format.hpp"
#include <string>
#include <utility>
inline auto fmt_r(boost::format & format) -> boost::format & {return format;}
template<typename T, typename... Args>
auto fmt_r(boost::format & format, T && val, Args &&... args) -> boost::format & {
return fmt_r(format % std::forward<T>(val), std::forward<Args>(args)...);
}
template<typename... Args>
auto fmt(const std::string & format_str, Args &&... args) -> std::string {
boost::format format(std::move(format_str));
fmt_r(format, std::forward<Args>(args)...);
return format.str();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment