Boost logo

Boost :

Subject: Re: [boost] [serialization] serializing std::string*
From: Zach Laine (whatwasthataddress_at_[hidden])
Date: 2008-12-17 09:17:53


> Zach Laine wrote:
>> It appears that std::string* is not serializable.
>
> I believe that it is serialzable - but it won't be tracked - which
> is probably not what you want.

FWIW, some_archive & some_std_string doesn't even compile with Boost
1.36 and 1.37, with GCC 4.1.0.

>> I have need to
>> serialize them, and I'm considering adding the old, unused code in
>> boost/serialization/string.hpp (the stuff #if 0-ed out and marked with
>> "left over from a previous incarnation - strings are now always
>> primitive types") to serialize std::string*'s. I have 2 questions
>> before doing so.
>>
>> 1) What is the rationale for making std::string a primitive,
>> track_never type? After an extensive rereading of the docs, I'm left
>> with only a hazy understanding of what the implications are for
>> primitive vs. non-primitive status.
>
> I used std::string in the archive header. In order to avoid a circular
> dependency, I made std::string primitive. I wasn't happy about this
> because it broke the identity between serialization::primitive and
> the normal usage of the phrase "prmitive type". But it was just too
> hard to do any other way. Maybe someday that might be looked
> at again.

So, why didn't you do a trick like the one used below, and save a
std::string-derived type instead of a std::string? Now users have to
figure out this trick and presumably have to post to this list, since
none of this is documented AFAICT.

>> 2) Can Robert (or anyone else) give me a sense for how likely I am to
>> get myself into trouble doing this? If it matters, I don't need to be
>> able to read old archives containing std::string's.
>
> I would recommend something else:
>
> class my_serializable_string : public std::string {
> ....
> };
>
> ar << static_cast<my_serialzable_string *>(some_std_string);
> ....

Well that works, so thanks! But a little note about this should
really be in the docs, no?

Zach


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk