waiter: modernize the waiter interface
[lttng-tools.git] / src / common / format.hpp
index 67509c275bad365ee23c2bd86ec7ab6fe44df5aa..c1ab3d54ddc33cad2fb4a2b1c91aeab7ae2338dc 100644 (file)
@@ -9,8 +9,9 @@
 
 #include <common/macros.hpp>
 
-#include <string>
 #include <cxxabi.h>
+#include <string>
+#include <utility>
 
 DIAGNOSTIC_PUSH
 DIAGNOSTIC_IGNORE_SUGGEST_ATTRIBUTE_FORMAT
@@ -42,4 +43,16 @@ struct formatter<std::type_info> : formatter<std::string> {
 };
 } /* namespace fmt */
 
+namespace lttng {
+template <typename... FormattingArguments>
+std::string format(FormattingArguments&&...args)
+{
+       try {
+               return fmt::format(std::forward<FormattingArguments>(args)...);
+       } catch (const fmt::format_error& ex) {
+               return std::string("Failed to format string: ") += ex.what();
+       }
+}
+} /* namespace lttng */
+
 #endif /* LTTNG_FORMAT_H */
This page took 0.024753 seconds and 4 git commands to generate.