From 601d546b8452159c38d65231d52f0dbd05e793d2 Mon Sep 17 00:00:00 2001 From: Michael Thies Date: Sun, 27 Aug 2023 18:58:03 +0200 Subject: Add explicit fmt::formatter for nlohmann::basic_json The formatter is based on fmt's ostream_formatter, using the provided operator<<(std::ostream&) of nlohmann::basic_json. This is required to allow compilation against fmt 10.x Co-authored-by: Oliver Reiche --- src/utils/cpp/json.hpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/utils/cpp/json.hpp') diff --git a/src/utils/cpp/json.hpp b/src/utils/cpp/json.hpp index aed2f3f4..9fd2d66d 100644 --- a/src/utils/cpp/json.hpp +++ b/src/utils/cpp/json.hpp @@ -21,6 +21,7 @@ #include #include +#include "fmt/ostream.h" #include "gsl/gsl" #include "nlohmann/json.hpp" #include "src/utils/cpp/gsl.hpp" @@ -212,4 +213,10 @@ namespace detail { return old_abbrev; } +// Use nlohmann::basic_json::operator<<() for formatting via libfmt. +// This explicit template specialization seems to be required starting with +// libfmt 10.x. +template <> +struct fmt::formatter> : ostream_formatter {}; + #endif // INCLUDED_SRC_UTILS_CPP_JSON_HPP -- cgit v1.2.3