Boost logo

Boost Users :

Subject: [Boost-users] serialization: 2-arg template free function serialize
From: Hicham Mouline (hicham_at_[hidden])
Date: 2010-12-30 13:37:22


Robert,

I have a number of types for which I've implemented the free serialize template function.
I have also a number of fusion sequences. This is the code I came up with:

namespace boost
{
namespace serialization
{

template <typename Archive>
class SerializeMemberOfFusionSeq; /// fwd decl

template <typename Archive, typename Seq>
typename boost::enable_if_c<boost::fusion::traits::is_sequence<Seq>::value, void>::type
serialize(Archive& ar, Seq& seq, unsigned int)
{
  boost::fusion::for_each(seq, SerializeMemberOfFusionSeq<Archive>(ar));
}

template <typename Archive>
class SerializeMemberOfFusionSeq {
public:
  SerializeMemberOfFusionSeq(Archive& ar)
  : ar_(ar)
  {}

  template <typename T>
  void operator()(T& t) const
  {
    ar_ & t;
  }

private:
  Archive& ar_;
};

}
}

Is the serialization library able to find the serialize() function this way?

regards,


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