Serialization compile issue
Hello, I am trying to serialize std containers via boost::serialization, but I am unable to get even simple code samples to compile. I used the serialization test_map.cpp as a guide to arrive at the very simple code that follows: --- snip --- #include <boost/serialization/map.hpp> #include <boost/serialization/string.hpp> #include <boost/serialization/nvp.hpp> #include <boost/archive/xml_oarchive.hpp> #include <iostream> #include <string> #include <map> int main() { std::map<std::string, std::string> data; data.insert(std::make_pair("a", "b")); data.insert(std::make_pair("b", "c")); data.insert(std::make_pair("c", "d")); boost::archive::xml_oarchive oa(std::cout); oa << boost::serialization::make_nvp("data", data); return 0; } --- snip --- Can anyone spot misuse above, or give me some clue as to why this won't compile? I am using boost 1.33.1, with GCC 4.1.1. If I change 'data' to be a simple string, serialization works, but if I use any std::container type (I've tried vector<string>, list<string>, and map<string,string> so far), I get an error of the following form: /usr/include/boost-1_33_1/boost/archive/detail/oserializer.hpp:131: error: invalid use of undefined type 'T3', where T1 = string T2 = list<T1> T3 = struct boost::serialization::extended_type_info_null<T2> /usr/include/boost-1_33_1/boost/serialization/type_info_implementation.hpp:26: error: declaration of 'T3', where T1 = string T2 = list<T1> T3 = struct boost::serialization::extended_type_info_null<T2> /usr/include/boost-1_33_1/boost/archive/detail/oserializer.hpp:132: error: invalid use of undefined type 'T3', where T1 = string T2 = list<T1> T3 = struct boost::serialization::extended_type_info_null<T2> /usr/include/boost-1_33_1/boost/serialization/type_info_implementation.hpp:26: error: declaration of 'T3', where T1 = string T2 = list<T1> T3 = struct boost::serialization::extended_type_info_null<T2> Any assistance would be greatly appreciated. - C.
Try the following change. Read the explanation in the "rationale" section. Robert Ramey Cory Omand wrote:
Hello,
I am trying to serialize std containers via boost::serialization, but I am unable to get even simple code samples to compile. I used the serialization test_map.cpp as a guide to arrive at the very simple code that follows:
--- snip --- #include <boost/serialization/map.hpp> #include <boost/serialization/string.hpp> #include <boost/serialization/nvp.hpp> #include <boost/archive/xml_oarchive.hpp> #include <iostream> #include <string> // not necessary - but does no harm #include <map> // not necessary - but does no harm
int main() { std::map<std::string, std::string> data; data.insert(std::make_pair("a", "b")); data.insert(std::make_pair("b", "c")); data.insert(std::make_pair("c", "d"));
const std::map<std::string, std::string> & data_ref = data;
boost::archive::xml_oarchive oa(std::cout); oa << boost::serialization::make_nvp("data", dataref);
return 0; } --- snip ---
Can anyone spot misuse above, or give me some clue as to why this won't compile?
I am using boost 1.33.1, with GCC 4.1.1. If I change 'data' to be a simple string, serialization works, but if I use any std::container type (I've tried vector<string>, list<string>, and map<string,string> so far), I get an error of the following form:
/usr/include/boost-1_33_1/boost/archive/detail/oserializer.hpp:131: error: invalid use of undefined type 'T3', where T1 = string T2 = list<T1> T3 = struct boost::serialization::extended_type_info_null<T2> /usr/include/boost-1_33_1/boost/serialization/type_info_implementation.hpp:26: error: declaration of 'T3', where T1 = string T2 = list<T1> T3 = struct boost::serialization::extended_type_info_null<T2> /usr/include/boost-1_33_1/boost/archive/detail/oserializer.hpp:132: error: invalid use of undefined type 'T3', where T1 = string T2 = list<T1> T3 = struct boost::serialization::extended_type_info_null<T2> /usr/include/boost-1_33_1/boost/serialization/type_info_implementation.hpp:26: error: declaration of 'T3', where T1 = string T2 = list<T1> T3 = struct boost::serialization::extended_type_info_null<T2>
Any assistance would be greatly appreciated.
- C.
On 9/12/07, Robert Ramey <ramey@rrsd.com> wrote:
Try the following change.
Read the explanation in the "rationale" section.
Hi Robert, Thanks for your reply. I actually did read the rationale section prior to coding this example. However, I would have expected the STATIC_ASSERT trap if I was passing the wrong thing to the serializer (as I did while trying to serialize pointers in a different example). I ended up with the sample code I attached to the previous mail via the serialization test 'test_map.cpp', which does not serialize via a const ref to the map. When I change my code as you suggest, I still get the same error about 'incomplete type used in name specifier' for boost::serialization::extended_type_info_null<pair<const string, string> >. I have attached a log including the complete set of errors I get when compiling the sample. Regards, Cory.
On 9/13/07, Cory Omand <coryomand@gmail.com> wrote:
On 9/12/07, Robert Ramey <ramey@rrsd.com> wrote:
Try the following change.
Read the explanation in the "rationale" section.
Hi Robert,
Thanks for your reply. I actually did read the rationale section prior to coding this example. However, I would have expected the STATIC_ASSERT trap if I was passing the wrong thing to the serializer (as I did while trying to serialize pointers in a different example). I ended up with the sample code I attached to the previous mail via the serialization test 'test_map.cpp', which does not serialize via a const ref to the map.
When I change my code as you suggest, I still get the same error about 'incomplete type used in name specifier' for boost::serialization::extended_type_info_null<pair<const string, string> >. I have attached a log including the complete set of errors I get when compiling the sample.
Attachment fell off.
participants (2)
-
Cory Omand
-
Robert Ramey