Boost logo

Boost Users :

Subject: Re: [Boost-users] [Serialization] This compiles; but does it work?
From: Bjorn Reese (breese_at_[hidden])
Date: 2016-02-19 05:02:11


On 02/19/2016 04:20 AM, Merrill Cornish wrote:

> Can anyone tell me if this will work, or do I need to implement the
> serialize() function?

When you are doing different things for the input and output archives
then it is better to split serialization into load and save:

#include <boost/filesystem/path.hpp>
#include <boost/serialization/split_free.hpp>

namespace boost { namespace serialization {

template <typename Archive>
void serialize(Archive& ar,
                filesystem::path& p,
                const unsigned int version)
{
     split_free(ar, p, version);
}

template<class Archive>
void save(Archive & ar,
           const filesystem::path& p,
           unsigned int version)
{
     ar << p.string();
}

template<class Archive>
void load(Archive & ar,
           filesystem::path& p,
           unsigned int version)
{
     std::string data;
     ar >> data;
     p = data;
}

}}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net