79420269

Date: 2025-02-07 09:00:25
Score: 1
Natty:
Report link

The answer provided by @3CxEZiVlQ is great. My project is not using a C++20 capable compiler but I was able to modify the code to work with an older compiler. For anybody else stuck with an older C++ compiler this is the code I used:

template <typename T>
struct fmt::formatter<T, std::enable_if_t<std::is_base_of<google::protobuf::Message, T>::value, char>>
    : fmt::formatter<string>
{
    auto format(const T& message, format_context& ctx) const
    {
        auto result = fmt::format("{}", message.DebugString());
        return fmt::formatter<std::string>::format(result, ctx);
    }
};
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @3CxEZiVlQ
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Glenn Coombs