15 #include <nlohmann/json.hpp>
16 #include <immer/array.hpp>
17 #include <immer/flex_vector.hpp>
18 #include <immer/map.hpp>
19 #include <boost/hana/type.hpp>
20 #include <lager/util.hpp>
38 [](
auto t) -> decltype((
void)std::declval<
typename decltype(t)::type>().empty()) {});
40 struct AddToJsonIfNeededT
43 static void call(
json &j, std::string name, T &&arg) {
44 using Type = std::decay_t<T>;
47 j[name] = std::forward<T>(arg);
50 j[name] = std::forward<T>(arg);
56 struct AddToJsonIfNeededT<
std::optional<U>>
59 static void call(
json &j, std::string name, T &&arg) {
60 if (arg.has_value()) {
61 j[name] = std::forward<T>(arg).value();
67 struct AddToJsonIfNeededT<JsonWrap>
70 static void call(
json &j, std::string name, T &&arg) {
71 if (!arg.get().is_null()) {
72 j[name] = std::forward<T>(arg).get();
82 detail::AddToJsonIfNeededT<std::decay_t<T>>::call(j, name, std::forward<T>(arg));
89 std::enable_if_t<!std::is_same_v<std::decay_t<MapT>,
json>
90 && !std::is_same_v<std::decay_t<MapT>, JsonWrap>,
int> = 0>
93 for (
auto kv : std::forward<MapT>(arg)) {
101 for (
auto kv : arg.items()) {
109 using namespace std::string_literals;
112 using Variant = std::variant<std::string, JsonWrap, Null>;
119 constexpr
operator T()
const {
136 typename std::add_lvalue_reference<T>::type
declref() noexcept;
141 template <
class T,
class V>
142 struct adl_serializer<immer::map<T, V>> {
144 if constexpr (std::is_same_v<T, std::string>) {
146 for (
auto [k, v] : map) {
151 for (
auto [k, v] : map) {
159 immer::map<T, V> ret;
160 if constexpr (std::is_same_v<T, std::string>) {
161 for (
const auto &[k, v] : j.items()) {
162 ret = std::move(ret).set(k, v);
165 for (std::size_t i = 0; i < j.size(); i += 2) {
166 ret = std::move(ret).set(j[i], j[i+1]);
174 struct adl_serializer<immer::array<T>> {
178 j.push_back(
json(i));
185 for (
const auto &i : j) {
186 ret = std::move(ret).push_back(i);
194 struct adl_serializer<immer::flex_vector<T>> {
198 j.push_back(
json(i));
203 immer::flex_vector<T> ret;
205 for (
const auto &i : j) {
206 ret = std::move(ret).push_back(i.get<T>());
216 std::visit(lager::visitor{
217 [&j](std::string i) { j = i; },
225 var = j.get<std::string>();
226 }
else if (j.is_null()) {