Boost logo

Boost Users :

Subject: Re: [Boost-users] [tuple] [serialization] serialize a tuple
From: OvermindDL1 (overminddl1_at_[hidden])
Date: 2009-08-24 17:40:44


On Mon, Aug 24, 2009 at 2:38 PM, Nick Edmonds<ngedmond_at_[hidden]> wrote:
> On Aug 24, 2009, at 2:23 PM, Dmitry Vinogradov wrote:
>
>> Stefan Strasser wrote:
>>>
>>> Am Monday 24 August 2009 18:13:02 schrieb Dmitry Vinogradov:
>>>>
>>>> How to serialize a tuple?
>>>> Where are no boost/serialization/tuple.hpp, nor
>>>> boost/tuple/tuple_serialization.hpp...
>>>
>>> if there is no builtin support for tuple (I don't know), have look at the
>>> serialization function of std::pair in  serialization/utility.hpp to see how
>>> it's done.
>>> or in the documentation under "free function".
>>
>> Thanks, I'll do it by myself.
>> BTW, do you know the reason why tuple serialization is missing in the
>> Boost library?
>
> IIRC the reason is (was?) that Boost.Tuple is implemented using a cons-list
> and can be most efficiently serialized using this implementation detail.
>  Serializing any TR1-compatible tuple implementation means that you'd need
> to build around the get<N> templates, which is more work for the compiler.
>  Alternately you can do a bunch of fancy Boost.Preprocessor tricks to make
> both work, but that seems like a lot of work.  That being said, I'm all for
> adding support to Boost.Serialization for serializing Boost.Tuple even if it
> does use knowledge of the cons-list implementation, it would allow me to
> remove my own implementation of serialization for Boost.Tuple from quite a
> few projects.
>
> Of course boost::fusion::tuple provides tuple_size< >, which makes
> serializing it really easy, so maybe switching to boost::fusion::tuple is
> the easiest (best?) approach.

Boost.Fusion has functions to convert such things to things it can
handle, and yes, Boost.Fusion is so much better for this stuff, I
actually use it for functionality like this.


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