Merge pull request #3441 from tchaikov/fmt-format-const

This commit is contained in:
Alexis Rouillard 2024-07-16 08:12:29 +02:00 committed by GitHub
commit f6ff6492ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 3 deletions

View File

@ -92,7 +92,7 @@ struct formatter<pow_format> {
template <> template <>
struct formatter<Glib::ustring> : formatter<std::string> { struct formatter<Glib::ustring> : formatter<std::string> {
template <typename FormatContext> template <typename FormatContext>
auto format(const Glib::ustring& value, FormatContext& ctx) { auto format(const Glib::ustring& value, FormatContext& ctx) const {
return formatter<std::string>::format(static_cast<std::string>(value), ctx); return formatter<std::string>::format(static_cast<std::string>(value), ctx);
} }
}; };

View File

@ -14,14 +14,14 @@
template <> template <>
struct fmt::formatter<Glib::VariantBase> : formatter<std::string> { struct fmt::formatter<Glib::VariantBase> : formatter<std::string> {
bool is_printable(const Glib::VariantBase& value) { bool is_printable(const Glib::VariantBase& value) const {
auto type = value.get_type_string(); auto type = value.get_type_string();
/* Print only primitive (single character excluding 'v') and short complex types */ /* Print only primitive (single character excluding 'v') and short complex types */
return (type.length() == 1 && islower(type[0]) && type[0] != 'v') || value.get_size() <= 32; return (type.length() == 1 && islower(type[0]) && type[0] != 'v') || value.get_size() <= 32;
} }
template <typename FormatContext> template <typename FormatContext>
auto format(const Glib::VariantBase& value, FormatContext& ctx) { auto format(const Glib::VariantBase& value, FormatContext& ctx) const {
if (is_printable(value)) { if (is_printable(value)) {
return formatter<std::string>::format(static_cast<std::string>(value.print()), ctx); return formatter<std::string>::format(static_cast<std::string>(value.print()), ctx);
} else { } else {