Boost logo

Boost Users :

Subject: [Boost-users] [serialization] loading a map having a const mapped value type
From: Marco Canini (marco.canini_at_[hidden])
Date: 2009-08-31 10:55:28


Hi all,

I'm unable to address this use case of the serialization library.
I have a standard map in which the mapped value is const:
map<string, const Protocol *> _table;

My serialize is very simple:
ar & _table;

(the test case source code is attached)

However, this can't be compiled as I get many errors related to the
loading code inside boost::serialization:

/usr/include/boost/archive/detail/iserializer.hpp:488: error:
reinterpret_cast from type 'const Protocol**' to type 'void**' casts away
constness

/usr/include/boost/archive/detail/iserializer.hpp:491: error: no matching
function for call to
'boost::archive::detail::load_pointer_type<boost::archive::text_iarchive,
const Protocol*>::pointer_tweak(const
boost::serialization::extended_type_info&, const Protocol*&, const
Protocol&)'

/usr/include/boost/serialization/access.hpp:109: error: passing 'const
Protocol' as 'this' argument of 'void Protocol::serialize(Archive&,
unsigned int) [with Archive = boost::archive::text_iarchive]' discards
qualifiers
/usr/include/boost/archive/detail/iserializer.hpp: In member function
'void boost::archive::detail::pointer_iserializer<T,
Archive>::load_object_ptr(boost::archive::detail::basic_iarchive&, void*&,
unsigned int) const [with T = const Protocol, Archive =
boost::archive::text_iarchive]':

/usr/include/boost/archive/detail/iserializer.hpp:299: error: invalid
conversion from 'const void*' to 'void*'
/usr/include/boost/archive/detail/iserializer.hpp:307: error: invalid
conversion from 'const void*' to 'void*'
/usr/include/boost/archive/detail/iserializer.hpp:307: error:
initializing argument 1 of 'void
boost::archive::detail::basic_iarchive::next_object_pointer(void*)'

/usr/include/boost/serialization/access.hpp:123: error: invalid conversion
 from 'const void*' to 'void*'
/usr/include/boost/serialization/access.hpp:123: error: initializing
argument 2 of 'void* operator new(size_t, void*)'
/usr/include/boost/serialization/access.hpp:123: error: no matching
function for call to 'Protocol::Protocol()'

/usr/include/boost/archive/detail/iserializer.hpp:555: error: invalid
application of 'sizeof' to incomplete type
'boost::STATIC_ASSERTION_FAILURE<false>'
/usr/include/boost/archive/detail/iserializer.hpp:555: error: invalid
application of 'sizeof' to incomplete type
'boost::STATIC_ASSERTION_FAILURE<false>'

Can somebody share his wisdom on this please?
Thanks!

-- 
Marco Canini



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net