Skip to content

Commit

Permalink
allow json cereal to have missing NVP and fall back to default constr…
Browse files Browse the repository at this point in the history
…ucting the field
  • Loading branch information
asa committed Nov 1, 2024
1 parent 503ea6a commit 6ec6eea
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lager/extra/derive/cereal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,18 @@
cereal::make_nvp(BOOST_PP_STRINGIZE(elem__), x.elem__)

#define LAGER_DERIVE_IMPL_CEREAL_MEMBERS_NON_EMPTY__(r__, members__) \
ar(BOOST_PP_SEQ_FOR_EACH_I_R( \
r__, LAGER_DERIVE_IMPL_CEREAL_ITER__, _, members__));
try { \
ar(BOOST_PP_SEQ_FOR_EACH_I_R( \
r__, LAGER_DERIVE_IMPL_CEREAL_ITER__, *, members__)); \
} catch (const cereal::Exception&) { \
/* Default construct all members */ \
BOOST_PP_SEQ_FOR_EACH_R( \
r__, LAGER_DERIVE_IMPL_DEFAULT__, *, members__); \
}

// Helper macro to default construct each member
#define LAGER_DERIVE_IMPL_DEFAULT__(r__, data__, elem__) \
x.elem__ = decltype(x.elem__){};

#define LAGER_DERIVE_IMPL_CEREAL_MEMBERS_EMPTY__(r__, members__)

Expand Down

0 comments on commit 6ec6eea

Please sign in to comment.