Boost logo

Boost :

Subject: Re: [boost] [serialization] serializing std::string*
From: Robert Ramey (ramey_at_[hidden])
Date: 2008-12-16 20:33:00


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.

> 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.

> 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);
....

Robert Ramey

>
> Thanks,
> Zach Laine
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost


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