|
Boost : |
From: Jeff Garland (jeff_at_[hidden])
Date: 2005-08-23 19:44:31
On Tue, 23 Aug 2005 22:49:14 +0200, Loïc Joly wrote
> Hello everybody,
>
> I've read the rationale for only allowing const trackable objects,
> but here is my problem :
You'll probably want to search the mail archive -- there's been a long
'debate' about the merits of the enforcement of this in 1.33. As I expected
it has taken only a few days to draw your email and a bug tracker request on
the subject...
> I want to serialize the following class :
>
> class C : boost::noncopyable
> {
> public:
> void setData(string s) {data = s;}
> //...
> };
>
> int main()
> {
> C c;
> c.setData("Hello world");
> vector <C*> v;
> v.push_back(&c);
> //...
> ar << c << c;
> }
>
> To have a c with meaningfull data, it cannot be const.
> I cannot create a local object that is a copy of the object (it is
> noncopyable)
> I do not think making the object untracked would be a good idea in
> this case (I might be wrong ?) So far, the best way I found to be
> able to serialize this object is :
>
> C const & cForSerialize = c;
> ar << cForSerialize << cForSerialize;
>
> But I do not think this is really elegant code. Is there a better
> alternative ?
So we could direct people to the docs we add the the following to the
date-time docs:
NOTE: due to a change in the serialization library interface, it is now
required that all streamable objects be const prior to writing to the archive.
The following template function will allow for this (and is used in the
date_time tests). At this time no special steps are necessary to read from an
archive.
template<class archive_type, class T>
void save_to(archive_type& ar, const T& val)
{
ar << val;
}
http://www.boost.org/doc/html/date_time/serialization.html
Jeff
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk