22 #include <type_traits> 29 inline string formatHelper(
const char* format_string, ...) {
33 va_start(argptr, format_string);
34 int size = vsnprintf(
nullptr, 0, format_string, argptr);
39 va_start(argptr, format_string);
40 string result(size, 0);
41 CHECK(vsnprintf(result.data(), size + 1, format_string, argptr) == size);
48 T formatArg(T value) {
49 static_assert(is_scalar_v<T>,
"Only scalar values and strings can be formatted");
53 inline const char* formatArg(
const string& s) {
67 template <
class... ARGS>
68 string format(
const char* format_string, ARGS&&... args) {
69 CHECK(format_string !=
nullptr);
70 return internal::formatHelper(format_string, internal::formatArg(args)...);
Generic utilities.
Definition: exception.h:24
string format(const char *format_string, ARGS &&... args)
A minimalistic string formatting built on top of the C-formatting facilities (xprintf formatting) ...
Definition: format.h:68