49void to_json(nlohmann::json& j,
const T& value) {
50 j = nlohmann::json::object();
52#if CALIB_HAS_PFR_CORE_NAME
53 constexpr auto names = boost::pfr::names_as_array<T>();
56 boost::pfr::for_each_field(value, [&](
auto const& field)
mutable {
58 const std::string n_key = std::string(names[idx]);
59 const bool have_named = !n_key.empty();
64 if (have_named) j[n_key] = *field;
68 if (have_named) j[n_key] = field;
74 boost::pfr::for_each_field(value, [&](
auto const& field)
mutable {
77 if (field) j[i_key] = *field;
90#if CALIB_HAS_PFR_CORE_NAME
91 constexpr auto names = boost::pfr::names_as_array<T>();
94 boost::pfr::for_each_field(value, [&](
auto& field)
mutable {
96 const std::string n_key = std::string(names[idx]);
97 const bool have_named = !n_key.empty();
99 auto read_optional = [&](
auto& opt) {
103 const nlohmann::json* slot =
nullptr;
105 if (
auto it = j.find(n_key); it != j.end()) slot = &*it;
108 if (
auto it = j.find(i_key); it != j.end()) slot = &*it;
111 if (!slot || slot->is_null()) {
114 opt = slot->get<Inner>();
119 read_optional(field);
121 if (have_named && j.contains(n_key)) {
122 j.at(n_key).get_to(field);
123 }
else if (j.contains(i_key)) {
124 j.at(i_key).get_to(field);
127 j.at(have_named ? n_key : i_key).get_to(field);
134 boost::pfr::for_each_field(value, [&](
auto& field)
mutable {
139 if (
auto it = j.find(i_key); it == j.end() || it->is_null()) {
142 field = it->get<Inner>();
145 j.at(i_key).get_to(field);