Skip to content

Archive::{is_loading,is_saving}::value #360

Description

@headupinclouds

Is the following {is_loading,is_saving} type addition compatible with the cereal library? This would greatly improve compatibility with existing boost serialization code and is seemingly unobtrusive.

template<class ArchiveType, std::uint32_t Flags = 0>
  class OutputArchive : public detail::OutputArchiveBase
{
  public:
    typedef bool_<false> is_loading;  // <- proposal
    typedef bool_<true> is_saving;     // <- proposal
   // ...
};

This supports the following serialization pattern:

struct Bar
{
    template <typename Archive> void serialize(Archive &ar, const std::uint32_t version)
    {
        std::int16_t tmp = foo;
        if(Archive::is_loading::value)
        {
            ar & tmp;
            foo = tmp; // For illustration only
        }
        else
        {
            tmp = foo; // For illustration only
            ar & tmp;
        }
        ar & foo;
    }
    std::int32_t foo;
};

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions