Last active
January 26, 2017 23:09
-
-
Save cjameshuff/18646f6a6755a09c7bdbd552b10f4d52 to your computer and use it in GitHub Desktop.
boost::format with type-safe C-style format strings
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" | |
#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