NamedType icon indicating copy to clipboard operation
NamedType copied to clipboard

cereal serialization functions

Open pwm1234 opened this issue 4 years ago • 1 comments

It took me a little while to figure out how to best serialize a NamedType using cereal (which is the BEST C++ serialization library I have found - if someone knows of a better one, please let me know). I am not sure of a good way to add this to the fluent codebase, so I thought I would post this issue in case this is helpful to others.

Cereal Serialization using external minimal serialization functions as described in Serialization Functions documentation.

namespace fluent {
template <typename Archive,
          typename ValueType,
          typename TagType,
          template <typename>
          class... Skills>
void load_minimal(
    Archive&,
    NamedType<ValueType, TagType, Skills...>& nobj,
    typename NamedType<ValueType, TagType, Skills...>::UnderlyingType const& val)
{
    using Ntype = NamedType<ValueType, TagType, Skills...>;
    nobj = Ntype{val};
}

template <typename Archive,
          typename ValueType,
          typename TagType,
          template <typename> class... Skills>
auto save_minimal(Archive&,
                  const NamedType<ValueType, TagType, Skills...>& nobj)
{
    return nobj.get();
}
}  // namespace fluent

pwm1234 avatar Aug 26 '20 22:08 pwm1234

Thanks for the reference!

joboccara avatar Aug 28 '20 12:08 joboccara