summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Thies <mail@mhthies.de>2023-08-27 18:58:03 +0200
committerOliver Reiche <oliver.reiche@huawei.com>2023-08-28 13:58:51 +0200
commit601d546b8452159c38d65231d52f0dbd05e793d2 (patch)
tree75ceacaeeb21d658c1e134e5029c7e7bcbf616cf /src
parent2b2719c7507437d722ad673d8c563f1c54974770 (diff)
downloadjustbuild-601d546b8452159c38d65231d52f0dbd05e793d2.tar.gz
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 <oliver.reiche@huawei.com>
Diffstat (limited to 'src')
-rw-r--r--src/utils/cpp/TARGETS7
-rw-r--r--src/utils/cpp/json.hpp7
2 files changed, 13 insertions, 1 deletions
diff --git a/src/utils/cpp/TARGETS b/src/utils/cpp/TARGETS
index 73c5e462..7c05472f 100644
--- a/src/utils/cpp/TARGETS
+++ b/src/utils/cpp/TARGETS
@@ -16,7 +16,12 @@
{ "type": ["@", "rules", "CC", "library"]
, "name": ["json"]
, "hdrs": ["json.hpp"]
- , "deps": ["gsl", ["@", "json", "", "json"], ["@", "gsl", "", "gsl"]]
+ , "deps":
+ [ "gsl"
+ , ["@", "json", "", "json"]
+ , ["@", "gsl", "", "gsl"]
+ , ["@", "fmt", "", "fmt"]
+ ]
, "stage": ["src", "utils", "cpp"]
}
, "concepts":
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 <string>
#include <unordered_map>
+#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<nlohmann::basic_json<>> : ostream_formatter {};
+
#endif // INCLUDED_SRC_UTILS_CPP_JSON_HPP