Serialization bug with hash_map?
Hello,
I cannot really get the serializations to work for hash_maps. Using
maps, lists and vectors
everything works just fine.
Using the sample code pasted below (using a hash_map) gives the
following compilation-errors:
/usr/include/boost/serialization/access.hpp: In static member function `static
void boost::serialization::access::serialize(Archive&, T&, unsigned int)
[with Archive = boost::archive::text_oarchive, T = __gnu_cxx::hash_map
Hello,
We have the same problem in our project. The solution we have arrived
at is:
change "boost/serialization/hash_map.hpp" as below:
//#ifdef __GLIBCPP__
#include
Hello,
I cannot really get the serializations to work for hash_maps. Using maps, lists and vectors everything works just fine.
Using the sample code pasted below (using a hash_map) gives the following compilation-errors:
/usr/include/boost/serialization/access.hpp: In static member function `static void boost::serialization::access::serialize(Archive&, T&, unsigned int) [with Archive = boost::archive::text_oarchive, T = __gnu_cxx::hash_map
]': /usr/include/boost/serialization/serialization.hpp:78: instantiated from `void boost::serialization::serialize(Archive&, T&, unsigned int) [with Archive = boost::archive::text_oarchive, T = __gnu_cxx::hash_map ]' /usr/include/boost/serialization/serialization.hpp:121: instantiated from `void boost::serialization::serialize_adl(Archive&, T&, unsigned int) [with Archive = boost::archive::text_oarchive, T = __gnu_cxx::hash_map ]' /usr/include/boost/archive/detail/oserializer.hpp:148: instantiated from `void boost::archive::detail::oserializer ::save_object_data(boost::archive::detail::basic_oarchive&, const void*) const [with Archive = boost::archive::text_oarchive, T = __gnu_cxx::hash_map ]' /usr/include/boost/archive/detail/oserializer.hpp:243: instantiated from here /usr/include/boost/serialization/access.hpp:106: error: `serialize' undeclared (first use this function) /usr/include/boost/serialization/access.hpp:106: error: (Each undeclared identifier is reported only once for each function it appears in.) Changing the created class to "busmap" (based on std::map) everything works just fine! (The ONLY difference between the classes is the container-definition)
System specs:
Linux kernel version 2.4.26 g++ (GCC) 3.3.2 20031218 boost-1.32
Sample code compiled with: g++ -o test test.cpp -lboost_serialization-gcc-mt ==================================================
#include <fstream> #include
#include #include #include #include #include <map> class busmap { friend class boost::serialization::access; std::map
bus_serial_map; // Imaginary bus-serial-number to bus number lookup-table; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & bus_serial_map; } public: busmap(){} }; class bushashmap { friend class boost::serialization::access; __gnu_cxx::hash_map
bus_serial_map; // Imaginary bus-serial-number to bus number lookup-table; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & bus_serial_map; } public: bushashmap(){} }; int main() { // create and open a character archive for output std::ofstream ofs("filename"); boost::archive::text_oarchive oa(ofs);
// create class instance const bushashmap myBusMap;
// write class instance to archive oa << myBusMap; // close archive ofs.close();
// ... some time later restore the class instance to its orginal state // create and open an archive for input
std::ifstream ifs("filename", std::ios::binary); boost::archive::text_iarchive ia(ifs); // read class state from archive busmap myNewBusMap; ia >> myNewBusMap; // close archive ifs.close(); return 0; }
=======================================
Bug or my fault?? Can anyone help?
Best regards Peter
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
This message has been checked for viruses but the contents of an attachment may still contain software viruses, which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.
Very good call ! Chris Coleman wrote:
change "boost/serialization/hash_map.hpp" as below: //#ifdef __GLIBCPP__ #include
//#else //#include //#endif
Why should the above be necessary? Isn't __GLIBCPP_ the right switch to use?
and add the following lines to: "boost/config/stdlib/libstdcpp3.hpp" #define BOOST_HAS_HASH #define BOOST_STD_EXTENSION_NAMESPACE __gnu_cxx
Could someone who is more expert on the various gcc configuration issues make this change in the gcc configuration? At least in the developement environment?
This has been discussed before I think, although seems still to be an issue in 1.33 I believe. I think its due to the fact that there is no standardised hash_map map implementation.
I don't remember this being mentioned before. Robert Ramey
Robert Ramey wrote:
change "boost/serialization/hash_map.hpp" as below: //#ifdef __GLIBCPP__ #include
//#else //#include //#endif Why should the above be necessary? Isn't __GLIBCPP_ the right switch to use?
I believe the location of the header changed at some point from hash_map.hpp to etx/hash_map.hpp. They may also have changed the namespace from std:: to __gnu_cxx::. (This change is certainly the case between 2.95 and 3.3, but I'm unsure exactly when this happened) As a result in the project I work on I have a bunch of autoconf macros to determine which namespace / header location is correct to use. I think it is also the case with hash_set's too, although I have never used them with the serialization library. Cheers Chris This message has been checked for viruses but the contents of an attachment may still contain software viruses, which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.
So we should do .... what? I would like to see this addressed in the configuration headers. Robert Ramey Christopher Coleman wrote:
Robert Ramey wrote:
change "boost/serialization/hash_map.hpp" as below: //#ifdef __GLIBCPP__ #include
//#else //#include //#endif Why should the above be necessary? Isn't __GLIBCPP_ the right switch to use?
I believe the location of the header changed at some point from hash_map.hpp to etx/hash_map.hpp. They may also have changed the namespace from std:: to __gnu_cxx::. (This change is certainly the case between 2.95 and 3.3, but I'm unsure exactly when this happened)
As a result in the project I work on I have a bunch of autoconf macros to determine which namespace / header location is correct to use.
I think it is also the case with hash_set's too, although I have never used them with the serialization library.
participants (4)
-
Chris Coleman
-
Christopher Coleman
-
Peter Lindman
-
Robert Ramey