[Boost-users] [serialization] serializing an stl container.

52 views
Skip to first unread message

Lucas Meijer

unread,
Oct 21, 2005, 7:20:19 AM10/21/05
to Boost...@lists.boost.org
Hey,

I've been banging my head against the wall for hours on this one.
I'd like to serialize stl containers to an archive. Starting simple: a
vector<int>

This is what I think I should do:

1) include the proper support header file for the to be serialized
container.

#include <boost/serialization/vector.hpp>

2) create an archive, can be any type:

std::stringstream ss;
boost::archive::text_oarchive oa(ss);

3) operator<< my container into this archive:

const vector<int> myvec;
oa << myvec;

The "oa << myvec" generates lots of warnings, and when running it
anyway, it crashes in smart_cast.hpp

I've tried lots of containertypes, and creating them in other ways than
shown above, using a binary_oarchive, but it doesn't seem to make a
difference.

(int myint; oa << myint; works fine)

Does anybody see what I'm missing here?

Thanks, Lucas
_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Robert Ramey

unread,
Oct 21, 2005, 9:47:52 PM10/21/05
to boost...@lists.boost.org
what compiler are you running?
which version of boost are you running?
do the tests/examples run on your system?
what do the warnings say?

I would think what you've done below should work.

Robert Ramey

Lucas Meijer

unread,
Oct 22, 2005, 7:43:20 PM10/22/05
to boost...@lists.boost.org
Hey Robert,

first off, thanks for the work on the serialization library, it looks
really good so far.

sorry for not including this info in my original post.

> what compiler are you running?

Microsoft Visual Studio .NET 2003
boost succesfully built using boost.jam

> which version of boost are you running?

1_33_0

> do the tests/examples run on your system?

yes.

> what do the warnings say?

warning C4541: 'dynamic_cast' used on polymorphic type
'boost::archive::detail::basic_oarchive' with /GR-; unpredictable
behavior may result

(see full warning below.)

this is compiling the following code:

std::stringstream ss;
boost::archive::binary_oarchive oa(ss); //also tried with text_oarchive
std::vector<int> myvec;
myvec.push_back(12);
const std::vector<int>& ref = myvec; //seem to require a reference.
oa << ref;

> I would think what you've done below should work.

thanks for the realitycheck,

Lucas

c:\Boost\include\boost-1_33\boost\smart_cast.hpp(76) : warning C4541:
'dynamic_cast' used on polymorphic type
'boost::archive::detail::basic_oarchive' with /GR-; unpredictable
behavior may result
c:\Boost\include\boost-1_33\boost\smart_cast.hpp(87) : see
reference to function template instantiation 'T
boost::smart_cast_impl::reference<T>::polymorphic::cross::cast<U>(U &)'
being compiled
with
[
T=boost::archive::binary_oarchive &,
U=boost::archive::detail::basic_oarchive
]
c:\Boost\include\boost-1_33\boost\smart_cast.hpp(135) : see
reference to function template instantiation 'T
boost::smart_cast_impl::reference<T>::polymorphic::cast<U>(U &)' being
compiled
with
[
T=boost::archive::binary_oarchive &,
U=boost::archive::detail::basic_oarchive
]
c:\Boost\include\boost-1_33\boost\smart_cast.hpp(293) : see
reference to function template instantiation 'T
boost::smart_cast_impl::reference<T>::cast<U>(U &)' being compiled
with
[
T=boost::archive::binary_oarchive &,
U=boost::archive::detail::basic_oarchive
]

c:\Boost\include\boost-1_33\boost\archive\detail\oserializer.hpp(148) :
see reference to function template instantiation 'T
boost::smart_cast_reference<Archive&,boost::archive::detail::basic_oarchive>(U
&)' being compiled
with
[
T=boost::archive::binary_oarchive &,
Archive=boost::archive::binary_oarchive,
U=boost::archive::detail::basic_oarchive
]

c:\Boost\include\boost-1_33\boost\serialization\extended_type_info_typeid.hpp(69)
: while compiling class-template member function 'void
boost::archive::detail::oserializer<Archive,T>::save_object_data(boost::archive::detail::basic_oarchive
&,const void *) const'
with
[
Archive=boost::archive::binary_oarchive,
T=std::vector<int>
]

c:\Boost\include\boost-1_33\boost\archive\detail\oserializer.hpp(263) :
see reference to class template instantiation
'boost::archive::detail::oserializer<Archive,T>' being compiled
with
[
Archive=boost::archive::binary_oarchive,
T=std::vector<int>
]

c:\Boost\include\boost-1_33\boost\archive\detail\oserializer.hpp(262) :
while compiling class-template member function 'void
boost::archive::detail::save_non_pointer_type<Archive,T>::save_standard::invoke(Archive
&,const std::vector<_Ty> &)'
with
[
Archive=boost::archive::binary_oarchive,
T=std::vector<int>,
_Ty=int
]

c:\Boost\include\boost-1_33\boost\archive\detail\oserializer.hpp(272) :
see reference to class template instantiation
'boost::archive::detail::save_non_pointer_type<Archive,T>::save_standard'
being compiled
with
[
Archive=boost::archive::binary_oarchive,
T=std::vector<int>
]

c:\Boost\include\boost-1_33\boost\archive\detail\oserializer.hpp(270) :
while compiling class-template member function 'void
boost::archive::detail::save_non_pointer_type<Archive,T>::save_conditional::invoke(Archive
&,const std::vector<_Ty> &)'
with
[
Archive=boost::archive::binary_oarchive,
T=std::vector<int>,
_Ty=int
]

c:\Boost\include\boost-1_33\boost\archive\detail\oserializer.hpp(321) :
see reference to class template instantiation
'boost::archive::detail::save_non_pointer_type<Archive,T>::save_conditional'
being compiled
with
[
Archive=boost::archive::binary_oarchive,
T=std::vector<int>
]

c:\Boost\include\boost-1_33\boost\archive\detail\oserializer.hpp(309) :
while compiling class-template member function 'void
boost::archive::detail::save_non_pointer_type<Archive,T>::invoke(Archive
&,const std::vector<_Ty> &)'
with
[
Archive=boost::archive::binary_oarchive,
T=std::vector<int>,
_Ty=int
]

c:\Boost\include\boost-1_33\boost\archive\detail\oserializer.hpp(535) :
see reference to class template instantiation
'boost::archive::detail::save_non_pointer_type<Archive,T>' being compiled
with
[
Archive=boost::archive::binary_oarchive,
T=std::vector<int>
]

c:\Boost\include\boost-1_33\boost\archive\basic_binary_oarchive.hpp(70)
: see reference to function template instantiation 'void
boost::archive::save<Archive,T>(Archive &,T &)' being compiled
with
[
Archive=boost::archive::binary_oarchive,
T=const std::vector<int>
]

c:\Boost\include\boost-1_33\boost\archive\binary_oarchive.hpp(47) : see
reference to function template instantiation 'void
boost::archive::basic_binary_oarchive<Archive>::save_override<T>(T
&,int)' being compiled
with
[
Archive=boost::archive::binary_oarchive,
T=const std::vector<int>
]

c:\Boost\include\boost-1_33\boost\archive\detail\interface_oarchive.hpp(85)
: see reference to function template instantiation 'void
boost::archive::binary_oarchive_impl<Archive>::save_override<T>(T
&,int)' being compiled
with
[
Archive=boost::archive::binary_oarchive,
T=const std::vector<int>
]

c:\PetProjects\XtraDevelopment\CastmemberPropertyXtra\source\casset.cpp(480)
: see reference to function template instantiation 'Archive
&boost::archive::detail::interface_oarchive<Archive>::operator <<<const
std::vector<_Ty>>(T &)' being compiled
with
[
Archive=boost::archive::binary_oarchive,
_Ty=int,
T=const std::vector<int>
]
Linking...

Robert Ramey

unread,
Oct 22, 2005, 8:36:49 PM10/22/05
to boost...@lists.boost.org
I presume you are using VC 7.1 IDE. Make sure that the project properties
are set for C++ so that Enable Runtime Info is set to "Yes"

Robert Ramey

Lucas Meijer wrote:

Lucas Meijer

unread,
Oct 23, 2005, 5:11:29 AM10/23/05
to boost...@lists.boost.org
Robert Ramey wrote:
> I presume you are using VC 7.1 IDE. Make sure that the project properties
> are set for C++ so that Enable Runtime Info is set to "Yes"

!!! You're a star !!!

Spent hours and hours trying to figure out what I was doing wrong.
Is there a place for boost newbies like me that collects these sort of
problems-likely-to-run-into?

Thanks,

Lucas

SevenCat

unread,
Oct 23, 2005, 6:23:33 AM10/23/05
to BOOST Archives
there is nothing concern with BOOST, it's a C++ question.

c++ contains lots of traps ,everywhere

Robert Ramey

unread,
Oct 23, 2005, 11:36:19 AM10/23/05
to boost...@lists.boost.org
You might try the documentation
at
boost.org
documentation
serialization library
reference
implementation notes
specific compiler issues
VC 7.1

Robert Ramey

Lucas Meijer wrote:

Lucas Meijer

unread,
Oct 23, 2005, 1:46:04 PM10/23/05
to boost...@lists.boost.org
Robert Ramey wrote:
> You might try the documentation
> at
> boost.org
> documentation
> serialization library
> reference
> implementation notes
> specific compiler issues
> VC 7.1

Hey Robert,

Excuse me if I'm looking with my nose, but following this line I've only
found the documentation that I've looked at before posting here:

boost.org
documentation
serialization library
reference

the reference section has no implementation notes as far as I can see.

I did find the page you're referring to just now, by googling for
"implementation notes boost serialization", but it seems like it is not
being linked to from anywhere? I couldn't find it, nor could google.
link:http://www.boost.org/libs/serialization/doc/implementation.html
returns no results.

Bye, Lucas

Robert Ramey

unread,
Oct 23, 2005, 3:32:53 PM10/23/05
to boost...@lists.boost.org
Hmmm - something must be out of whack somewhere. I click on the link in
your email -
http://www.boost.org/libs/serialization/doc/implementation.html
and it goes right where I expect it to.

I don't know what else to say here.

Robert Ramey

Lucas Meijer wrote:

Lucas Meijer

unread,
Oct 23, 2005, 4:40:54 PM10/23/05
to boost...@lists.boost.org
Robert Ramey wrote:
> Hmmm - something must be out of whack somewhere. I click on the link in
> your email -
> http://www.boost.org/libs/serialization/doc/implementation.html
> and it goes right where I expect it to.
>
> I don't know what else to say here.

Sorry if I've been unclear here. What I meant was that I couldn't find
that document from any place inside the boost-serialize documentation. I
only found it because you emailed me the name of the document. I googled
that name, and google found the url for me.

If I follow the documentation-path you sent me, I get stuck at
"references". when I click the references link, I see no way to progress
to the implementation notes.

I've now found the implementation notes being linked to from the bottom
of the release notes page though, so it turns out I could have found out
myself.

Maybe linking to the implementation notes somewhere more in sight would
be a good idea, alltough I'm not sure how many people run into this.

Very glad things work now :)

Robert Ramey

unread,
Oct 23, 2005, 4:53:36 PM10/23/05
to boost...@lists.boost.org
On my browser, the serialization documentation shows up with a navigation
panel on the left
which expands and contracts the sections. This panel uses javascript so I'm
guessing you
don't have javascript enabled on your browser.

My intention has been that things should be navigable even without
javascript being enabled.
It looks like this intention hasn't been realized. I'll look into it.

Robert Ramey

Lucas Meijer wrote:
Reply all
Reply to author
Forward
0 new messages