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>
#include "common/assert.h"
#include "cpp-common/bt2s/string-view.hpp"
#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"
const char *_mStr = nullptr;
};
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 */
#endif /* BABELTRACE_CPP_COMMON_BT2C_C_STRING_VIEW_HPP */
#endif /* BABELTRACE_CPP_COMMON_BT2C_C_STRING_VIEW_HPP */