Boost logo

Boost Users :

From: Sohail Somani (sohail_at_[hidden])
Date: 2008-03-27 15:00:34


On Thu, 27 Mar 2008 15:27:46 -0300, Felipe Magno de Almeida wrote:

> Is there any plan to include this code to a tuple header?
> tuple_serialization.hpp ?

I think the best way to get it looked at would be to file a bug.

Anyway, if there was an is_tuple<T> metafunction, there would be a more
elegant way to do it:

// not compiled or tested
namespace boost { namespace serialization {

    template<typename TupleType,
             int Which>
    struct serialize
    {
      template<typename Archive>
      static void call(Archive & ar, TupleType & t)
      {
        ar & t.get<Which>();
        serialize<TupleType,Which-1>::call(ar,t);
      }
    };

    template<typename TupleType>
    struct serialize<TupleType,0>
    {
      template<typename Archive>
      static void call(Archive & ar, TupleType & t)
      {
        ar & t.get<0>();
      }
    };

    template<typename Archive, typename TupleType>
    typename boost::enable_if<is_tuple<TupleType>::value,void>::type
    void serialize(Archive & ar, TupleType & t, int fv)
    {
      return serialize<TupleType,TupleType::size-1>::call(ar,t);
    }

}}

-- 
Sohail Somani
http://uint32t.blogspot.com

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