3#ifndef STRING_FORMAT_H_
4#define STRING_FORMAT_H_
9template <
typename... Args>
10std::string string_format(
const std::string &format, Args... args) {
14 int size_s = std::snprintf(
nullptr, 0, format.c_str(), args...) + 1;
16 throw std::runtime_error(
"Error during formatting.");
20 auto size =
static_cast<size_t>(size_s);
21 std::unique_ptr<char[]> buf(
new char[size]);
24 std::snprintf(buf.get(), size, format.c_str(), args...);
26 return std::string(buf.get(), buf.get() + size - 1);