From 0fbfc96619ecff0dec648a82abe71d3ef85dd330 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Thu, 25 Jan 2024 10:05:13 +0800 Subject: [PATCH] db: add formatter for schema_tables::table_kind before this change, we rely on the default-generated fmt::formatter created from operator<<, but fmt v10 dropped the default-generated formatter. in this change, we define formatters for db::schema_tables::table_kind, and its operator<<() is still used by the homebrew generic formatter for std::map<>, so it is preserved. Refs #13245 Signed-off-by: Kefu Chai Closes scylladb/scylladb#16972 --- db/schema_tables.cc | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/db/schema_tables.cc b/db/schema_tables.cc index fdd102e58b..233cbfd33b 100644 --- a/db/schema_tables.cc +++ b/db/schema_tables.cc @@ -1040,12 +1040,29 @@ using keyspace_name = sstring; enum class table_kind { table, view }; -static std::ostream& operator<<(std::ostream& os, table_kind k) { - switch (k) { - case table_kind::table: return os << "table"; - case table_kind::view: return os << "view"; +} +} + +template <> struct fmt::formatter { + constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } + auto format(db::schema_tables::table_kind k, fmt::format_context& ctx) const { + switch (k) { + using enum db::schema_tables::table_kind; + case table: + return fmt::format_to(ctx.out(), "table"); + case view: + return fmt::format_to(ctx.out(), "view"); + } + abort(); } - abort(); +}; + +namespace db { +namespace schema_tables { + +static std::ostream& operator<<(std::ostream& os, table_kind k) { + fmt::print(os, "{}", k); + return os; } static constexpr std::initializer_list all_table_kinds = {