aboutsummaryrefslogtreecommitdiff
path: root/src/utils.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.h')
-rw-r--r--src/utils.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/utils.h b/src/utils.h
index 005e5be..77096e7 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -7,6 +7,7 @@
#include <map>
#include <sstream>
#include <memory>
+#include <optional>
#include <stdexcept>
#include <filesystem>
@@ -23,6 +24,23 @@ namespace nlohmann {
opt = std::shared_ptr<T>(T::create(j));
}
};
+
+ template <typename T> struct adl_serializer<std::optional<T>> {
+ static void to_json(json& j, const std::optional<T>& opt) {
+ if(opt) {
+ j = *opt;
+ } else {
+ j = nullptr;
+ }
+ }
+ static void from_json(const json& j, std::optional<T>& opt) {
+ if(j.is_null()) {
+ opt = std::optional<T>();
+ } else {
+ opt = j.get<T>();
+ }
+ }
+ };
}
namespace utils {