Robert Ramey wrote:
Oh then maybe you want:
void serialize(boost::archive::xml_iarchive & ar, std::map > & t,
const
unsigned int version){
// for each member in the map
ar & *it;
}
Ah, I was looking for that but missed it. I'm having trouble compiling
the load though as gcc doesnt like the map member's std::pair.first being
const. I'm sure I'm doing something incorrect that's blindingly obvious,
but I just can't see it. The code and compiler messages are below.
#include <map>
#include <fstream>
#include
#include // For std::pair
typedef boost::archive::xml_wiarchive iarchive;
typedef std::wifstream ifstream;
struct Mark {};
enum MarkId {low,median,high};
typedef std::map MarkMap;
void serialize(iarchive &ar, MarkMap & m, const unsigned int version)
{
MarkMap::iterator it;
for (it = m.begin() ; it != m.end(); ++it) {
ar & boost::serialization::make_nvp("item", *it);
}
}
int main(int argc, char* argv[])
{
ifstream ifs;
iarchive ar(ifs);
MarkMap marks;
ar >> boost::serialization::make_nvp("marks",marks);
}
gcc --version
gcc (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
g++ -c tsrz.cpp -I/usr/local/include -isystem /usr/local/include/boost-1_33 -isystem ./boost -g -Wall -Wno-non-virtual-dtor -Wno-inline -ftemplate-depth-255 -finline-functions -MMD -MF.deps/tsrz.d
/usr/local/include/boost-1_33/boost/archive/detail/iserializer.hpp: In function
`void boost::archive::load(Archive&, T&) [with Archive =
boost::archive::xml_wiarchive, T = const MarkId]':
/usr/local/include/boost-1_33/boost/archive/basic_xml_iarchive.hpp:80: instantiated from `void boost::archive::basic_xml_iarchive<Archive>::load_override(const boost::serialization::nvp<T>&, int) [with T = const MarkId, Archive = boost::archive::xml_wiarchive]'
/usr/local/include/boost-1_33/boost/archive/xml_wiarchive.hpp:78: instantiated from `void boost::archive::xml_wiarchive_impl<Archive>::load_override(T&, int) [with T = const boost::serialization::nvp<const MarkId>, Archive = boost::archive::xml_wiarchive]'
/usr/local/include/boost-1_33/boost/archive/detail/interface_iarchive.hpp:84: instantiated from `Archive& boost::archive::detail::interface_iarchive<Archive>::operator>>(T&) [with T = const boost::serialization::nvp<const MarkId>, Archive = boost::archive::xml_wiarchive]'
/usr/local/include/boost-1_33/boost/archive/detail/interface_iarchive.hpp:91: instantiated from `Archive& boost::archive::detail::interface_iarchive<Archive>::operator&(T&) [with T = const boost::serialization::nvp<const MarkId>, Archive = boost::archive::xml_wiarchive]'
/usr/local/include/boost-1_33/boost/serialization/utility.hpp:43: instantiated from `void boost::serialization::serialize(Archive&, std::pair&, unsigned int) [with Archive = boost::archive::xml_wiarchive, F = const MarkId, S = Mark]'
/usr/local/include/boost-1_33/boost/serialization/serialization.hpp:140: instantiated from `void boost::serialization::serialize_adl(Archive&, T&, unsigned int) [with Archive = boost::archive::xml_wiarchive, T = std::pair]'
/usr/local/include/boost-1_33/boost/archive/detail/iserializer.hpp:158: instantiated from `void boost::archive::detail::iserializer::load_object_data(boost::archive::detail::basic_iarchive&, void*, unsigned int) const [with Archive = boost::archive::xml_wiarchive, T = std::pair]'
/usr/local/include/boost-1_33/boost/mpl/if.hpp:67: instantiated from here
/usr/local/include/boost-1_33/boost/archive/detail/iserializer.hpp:544: `sizeof'
applied to incomplete type `boost::STATIC_ASSERTION_FAILURE<false>'
/usr/local/include/boost-1_33/boost/archive/detail/iserializer.hpp: In static
member function `static void boost::archive::detail::load_enum_type::invoke(Archive&, T&) [with Archive = boost::archive::xml_wiarchive, T =
const MarkId]':
/usr/local/include/boost-1_33/boost/archive/detail/iserializer.hpp:559: instantiated from `void boost::archive::load(Archive&, T&) [with Archive = boost::archive::xml_wiarchive, T = const MarkId]'
/usr/local/include/boost-1_33/boost/archive/basic_xml_iarchive.hpp:80: instantiated from `void boost::archive::basic_xml_iarchive<Archive>::load_override(const boost::serialization::nvp<T>&, int) [with T = const MarkId, Archive = boost::archive::xml_wiarchive]'
/usr/local/include/boost-1_33/boost/archive/xml_wiarchive.hpp:78: instantiated from `void boost::archive::xml_wiarchive_impl<Archive>::load_override(T&, int) [with T = const boost::serialization::nvp<const MarkId>, Archive = boost::archive::xml_wiarchive]'
/usr/local/include/boost-1_33/boost/archive/detail/interface_iarchive.hpp:84: instantiated from `Archive& boost::archive::detail::interface_iarchive<Archive>::operator>>(T&) [with T = const boost::serialization::nvp<const MarkId>, Archive = boost::archive::xml_wiarchive]'
/usr/local/include/boost-1_33/boost/archive/detail/interface_iarchive.hpp:91: instantiated from `Archive& boost::archive::detail::interface_iarchive<Archive>::operator&(T&) [with T = const boost::serialization::nvp<const MarkId>, Archive = boost::archive::xml_wiarchive]'
/usr/local/include/boost-1_33/boost/serialization/utility.hpp:43: instantiated from `void boost::serialization::serialize(Archive&, std::pair&, unsigned int) [with Archive = boost::archive::xml_wiarchive, F = const MarkId, S = Mark]'
/usr/local/include/boost-1_33/boost/serialization/serialization.hpp:140: instantiated from `void boost::serialization::serialize_adl(Archive&, T&, unsigned int) [with Archive = boost::archive::xml_wiarchive, T = std::pair]'
/usr/local/include/boost-1_33/boost/archive/detail/iserializer.hpp:158: instantiated from `void boost::archive::detail::iserializer::load_object_data(boost::archive::detail::basic_iarchive&, void*, unsigned int) const [with Archive = boost::archive::xml_wiarchive, T = std::pair]'
/usr/local/include/boost-1_33/boost/mpl/if.hpp:67: instantiated from here
/usr/local/include/boost-1_33/boost/archive/detail/iserializer.hpp:491: assignment
of read-only reference `t'