From 033f941a1c3f37741c587360c018ffe920c11f1f Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Wed, 10 Sep 2014 13:44:10 +0300 Subject: [PATCH] core: add sprint(fmt, ...) Similar to sprintf(), only type-safe. --- core/print.hh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/print.hh b/core/print.hh index 86f018d293..1fce216c34 100644 --- a/core/print.hh +++ b/core/print.hh @@ -45,4 +45,12 @@ print(const char* fmt, A&&... a) { return print(bfmt, std::forward(a)...); } +template +std::string +sprint(const char* fmt, A&&... a) { + boost::format bfmt(fmt); + apply_format(bfmt, std::forward(a)...); + return bfmt.str(); +} + #endif /* PRINT_HH_ */