|
Boost Users : |
From: Malte Clasen (news_at_[hidden])
Date: 2004-11-25 19:45:36
Robert Ramey wrote:
> The pimpl example demonstrates pretty much all I know about the issue.
Ok, I'm using that one now and it compiles fine.
But another issue appeared: The automatic serialization of nested
std::vectors fails under certain circumstances. I managed to isolate the
problem to the following case:
----------
// disable warnings that don't matter in this example
#pragma warning(disable:4511 4512 4244 4100 4267)
#include <boost/serialization/serialization.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <fstream>
#include <vector>
class A
{
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive &, const unsigned int) {}
};
template<typename T>
class B
{
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int /*version*/)
{
//ar.register_type< std::vector<T> >(); // workaround A
//ar & vT; // workaround B, part 1/2
ar & vvT; // this one fails
}
//std::vector<T> vT; // workaround B, part 2/2
std::vector< std::vector<T> > vvT;
};
void save()
{
std::ofstream ofs("test.dat");
boost::archive::text_oarchive oa(ofs);
B< boost::shared_ptr<A> > b_ptr_a;
oa << b_ptr_a;
}
void load()
{
std::ifstream ifs("test.dat");
boost::archive::text_iarchive ia(ifs);
B< boost::shared_ptr<A> > b_ptr_a;
ia >> b_ptr_a;
}
----------
The serialization of std::vector< std::vector<T> > fails to compile
(VC++ 7.1) unless one of the workarounds is used, that means some kind
of registration of std::vector<T>. Is that a known limitation? I found
nothing in the documentation about this case, but perhaps I overlooked
something.
Malte
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