[serialization] newbie question regarding serialization of std::list<int>

Hi everybody, I am new to the serialization library and encountered a simple problem which I couldn't solve. I'd like to serialize simple stl containers. A minimal example is #include <fstream> #include <list> #include <boost/serialization/list.hpp> #include <boost/archive/text_oarchive.hpp> int main(int argc, char** argv) { typedef std::list<int> List; List myList; myList.push_back(1); myList.push_back(2); myList.push_back(3); myList.push_back(4); std::ofstream ofs("archive.txt"); boost::archive::text_oarchive oa(ofs); oa << myList; } This doesn't compile under Linux using gcc-3.3 and boost-1.33.1 giving the following compiler error: /opt/toolkits/linux32/gcc-3.3/boost-1-33-1/include/boost-1_33_1/boost/archive/detail/oserializer.hpp:567: error: incomplete type `boost::STATIC_ASSERTION_FAILURE<false>' does not have member `value' Looking at the code at the given position hints that the type which should be serialized should be marked as track_never. I added the following command below the typedef of List BOOST_CLASS_TRACKING(List, boost::serialization::track_never) which also doesn't solve the problem... Maybe I am missing something very basic. I would be very thankful, if somebody could lift the curtain in front of my eyes ;-) Best Regards, Max

the << operator can only be used for "const" objects - the & operator can be used for anything. This is explained in the "rationale" section of the documentation. Robert Ramey Max Schoebinger wrote:
Hi everybody,
I am new to the serialization library and encountered a simple problem which I couldn't solve. I'd like to serialize simple stl containers. A minimal example is
#include <fstream> #include <list> #include <boost/serialization/list.hpp> #include <boost/archive/text_oarchive.hpp>
int main(int argc, char** argv) { typedef std::list<int> List;
List myList; myList.push_back(1); myList.push_back(2); myList.push_back(3); myList.push_back(4); std::ofstream ofs("archive.txt"); boost::archive::text_oarchive oa(ofs); oa << myList; }
This doesn't compile under Linux using gcc-3.3 and boost-1.33.1 giving the following compiler error:
/opt/toolkits/linux32/gcc-3.3/boost-1-33-1/include/boost-1_33_1/boost/archive/detail/oserializer.hpp:567: error: incomplete type `boost::STATIC_ASSERTION_FAILURE<false>' does not have member `value'
Looking at the code at the given position hints that the type which should be serialized should be marked as track_never. I added the following command below the typedef of List
BOOST_CLASS_TRACKING(List, boost::serialization::track_never)
which also doesn't solve the problem...
Maybe I am missing something very basic. I would be very thankful, if somebody could lift the curtain in front of my eyes ;-)
Best Regards,
Max

Hi, I also tried using the & operator, but this also results in a compiler error: /opt/toolkits/linux32/gcc-3.3/boost-1-33-1/include/boost-1_33_1/boost/archive/detail/oserializer.hpp:108: error: incomplete type 'boost::serialization::extended_type_info_null<std::list<int, std::allocator<int> > >' cannot be used to name a scope What would be a minimal example for serializing a std::list<int>? Thank you for your help! Max Robert Ramey schrieb:
the << operator can only be used for "const" objects - the & operator can be used for anything.
This is explained in the "rationale" section of the documentation.
Robert Ramey
Max Schoebinger wrote:
Hi everybody,
I am new to the serialization library and encountered a simple problem which I couldn't solve. I'd like to serialize simple stl containers. A minimal example is
#include <fstream> #include <list> #include <boost/serialization/list.hpp> #include <boost/archive/text_oarchive.hpp>
int main(int argc, char** argv) { typedef std::list<int> List;
List myList; myList.push_back(1); myList.push_back(2); myList.push_back(3); myList.push_back(4); std::ofstream ofs("archive.txt"); boost::archive::text_oarchive oa(ofs); oa << myList; }
This doesn't compile under Linux using gcc-3.3 and boost-1.33.1 giving the following compiler error:
/opt/toolkits/linux32/gcc-3.3/boost-1-33-1/include/boost-1_33_1/boost/archive/detail/oserializer.hpp:567: error: incomplete type `boost::STATIC_ASSERTION_FAILURE<false>' does not have member `value'
Looking at the code at the given position hints that the type which should be serialized should be marked as track_never. I added the following command below the typedef of List
BOOST_CLASS_TRACKING(List, boost::serialization::track_never)
which also doesn't solve the problem...
Maybe I am missing something very basic. I would be very thankful, if somebody could lift the curtain in front of my eyes ;-)
Best Regards,
Max

Hmmm I just compiled on my system with gcc 3.3, vc 7.1, and comeau all without problems. I'm using the current cvs HEAD but I wouldn't think that would make a difference: #include <fstream> #include <list> #include <boost/serialization/list.hpp> #include <boost/archive/text_oarchive.hpp> int main(int argc, char** argv) { typedef std::list<int> List; List myList; myList.push_back(1); myList.push_back(2); myList.push_back(3); myList.push_back(4); std::ofstream ofs("archive.txt"); boost::archive::text_oarchive oa(ofs); oa & myList; } Robert Ramey Max Schoebinger wrote:
Hi,
I also tried using the & operator, but this also results in a compiler error:
/opt/toolkits/linux32/gcc-3.3/boost-1-33-1/include/boost-1_33_1/boost/archive/detail/oserializer.hpp:108: error: incomplete type 'boost::serialization::extended_type_info_null<std::list<int, std::allocator<int> > >' cannot be used to name a scope
What would be a minimal example for serializing a std::list<int>?
Thank you for your help!
Max
Robert Ramey schrieb:
the << operator can only be used for "const" objects - the & operator can be used for anything.
This is explained in the "rationale" section of the documentation.
Robert Ramey
Max Schoebinger wrote:
Hi everybody,
I am new to the serialization library and encountered a simple problem which I couldn't solve. I'd like to serialize simple stl containers. A minimal example is
#include <fstream> #include <list> #include <boost/serialization/list.hpp> #include <boost/archive/text_oarchive.hpp>
int main(int argc, char** argv) { typedef std::list<int> List;
List myList; myList.push_back(1); myList.push_back(2); myList.push_back(3); myList.push_back(4); std::ofstream ofs("archive.txt"); boost::archive::text_oarchive oa(ofs); oa << myList; }
This doesn't compile under Linux using gcc-3.3 and boost-1.33.1 giving the following compiler error:
/opt/toolkits/linux32/gcc-3.3/boost-1-33-1/include/boost-1_33_1/boost/archive/detail/oserializer.hpp:567: error: incomplete type `boost::STATIC_ASSERTION_FAILURE<false>' does not have member `value'
Looking at the code at the given position hints that the type which should be serialized should be marked as track_never. I added the following command below the typedef of List
BOOST_CLASS_TRACKING(List, boost::serialization::track_never)
which also doesn't solve the problem...
Maybe I am missing something very basic. I would be very thankful, if somebody could lift the curtain in front of my eyes ;-)
Best Regards,
Max

At 1:21 PM +0100 3/15/06, Max Schoebinger wrote:
I also tried using the & operator, but this also results in a compiler error:
/opt/toolkits/linux32/gcc-3.3/boost-1-33-1/include/boost-1_33_1/boost/archive/detail/oserializer.hpp:108: error: incomplete type 'boost::serialization::extended_type_info_null<std::list<int, std::allocator<int> > >' cannot be used to name a scope
At 8:11 AM -0800 3/15/06, Robert Ramey wrote:
Hmmm I just compiled on my system with gcc 3.3, vc 7.1, and comeau all without problems. I'm using the current cvs HEAD but I wouldn't think that would make a difference:
The error encountered by Max is the same error I recently reported on the boost developers list, where there is an include order problem involving nvp.hpp. This may be another occurrence of that problem. Robert replied to my message that he believed it to be fixed post 1.33.1 in CVS; I've been too busy to actually verify that for my encounter with this problem yet, and just worked around the problem by tweaking the include order. Specifically, I found that nvp.hpp must be included after including the archive header. I note that nvp is being included indirectly through the chain <boost/serialization/list.hpp> <boost/serialization/collections_save_imp.hpp> <boost/serialization/nvp.hpp> <boost/serialization/collections_load_imp.hpp> <boost/serialization/nvp.hpp> There may be additional nested includes of nvp.hpp from list.hpp that I didn't bother to track down. Anyway, I suggest retrying with the program changed to include text_archive.hpp before including list.hpp, and report back. I'm without access to my Linux machine at the moment or I'd try it myself, since it looks like I'm using something close to the same toolchain and boost version as Max.
participants (3)
-
Kim Barrett
-
Max Schoebinger
-
Robert Ramey