cpp-common/bt2c: simplify CStringView formatter
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 15 Jan 2024 21:34:29 +0000 (16:34 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Mon, 29 Jan 2024 16:38:19 +0000 (11:38 -0500)
Use a format_as function instead of a full-fledged formatter.

Change-Id: I49a015a1c88a49cd7c4bab3ff1cbbf8cad8b6ba0
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11682
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
src/cpp-common/bt2c/c-string-view.hpp

index ddcf36c6df18e2fb3e4cbed693c6bbb39adbf19e..c1c8bf389c8bd50233bc56ae54bd602a5aceda5c 100644 (file)
@@ -13,7 +13,7 @@
 
 #include "common/assert.h"
 #include "cpp-common/bt2s/string-view.hpp"
-#include "cpp-common/vendor/fmt/core.h"
+#include "cpp-common/vendor/fmt/format.h"
 
 namespace bt2c {
 
@@ -169,24 +169,11 @@ private:
     const char *_mStr = nullptr;
 };
 
-} /* namespace bt2c */
-
-namespace fmt {
-
-template <>
-struct formatter<bt2c::CStringView>
+static inline const char *format_as(const CStringView& str)
 {
-    constexpr auto parse(format_parse_context& ctx) const -> format_parse_context::iterator
-    {
-        return ctx.end();
-    }
+    return str ? *str : "(null)";
+}
 
-    auto format(const bt2c::CStringView& str, format_context& ctx) const -> format_context::iterator
-    {
-        return str ? fmt::format_to(ctx.out(), "{}", *str) : fmt::format_to(ctx.out(), "(null)");
-    }
-};
-
-} /* namespace fmt */
+} /* namespace bt2c */
 
 #endif /* BABELTRACE_CPP_COMMON_BT2C_C_STRING_VIEW_HPP */
This page took 0.02499 seconds and 4 git commands to generate.