common: Add a default nullptr argument to make_unique_wrapper
[lttng-tools.git] / src / common / format.hpp
index 020766eb5ddd788dfd7c8114a6bd993e7817cfdf..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
@@ -26,11 +27,13 @@ DIAGNOSTIC_POP
 namespace fmt {
 template <>
 struct formatter<std::type_info> : formatter<std::string> {
-       template <typename FormatCtx>
-       typename FormatCtx::iterator format(const std::type_info& type_info, FormatCtx& ctx)
+       template <typename FormatContextType>
+       typename FormatContextType::iterator format(const std::type_info& type_info,
+                                                   FormatContextType& ctx)
        {
                int status;
-               auto demangled_name = abi::__cxa_demangle(type_info.name(), nullptr, 0, &status);
+               auto demangled_name =
+                       abi::__cxa_demangle(type_info.name(), nullptr, nullptr, &status);
                auto it = status == 0 ? formatter<std::string>::format(demangled_name, ctx) :
                                        formatter<std::string>::format(type_info.name(), ctx);
 
@@ -40,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.023355 seconds and 4 git commands to generate.