Re: [Boost-bugs] [Boost C++ Libraries] #5679: boost::serialization::primitive_type used with polymorphic archive fails to compile (was: Serialization of uuid with polymorphic archive fails to compile)

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #5679: boost::serialization::primitive_type used with polymorphic archive fails to compile (was: Serialization of uuid with polymorphic archive fails to compile)
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-07-13 20:59:27


#5679: boost::serialization::primitive_type used with polymorphic archive fails to
compile
----------------------------------+-----------------------------------------
  Reporter: boost@… | Owner: ramey
      Type: Bugs | Status: new
 Milestone: To Be Determined | Component: serialization
   Version: Boost 1.47.0 | Severity: Problem
Resolution: | Keywords: uuid serialization polymorphic
----------------------------------+-----------------------------------------
Changes (by boost@…):

  * version: Boost 1.44.0 => Boost 1.47.0

Comment:

 A bit of further investigation reveals this to be an issue with using
 boost::serialization::primitive_type and polymorphic archive types.

 UUID just happens to be a case.

 Here's a test to demonstrate:
 (Note: this was tested against 1.47; the problem is still present.)


 {{{
 #include <sstream>

 #include <boost/archive/polymorphic_binary_oarchive.hpp>
 #include <boost/archive/polymorphic_binary_iarchive.hpp>

 struct MyPrimitiveType
 {
     int n_;

     template <typename Ar>
     void serialize(Ar &ar, unsigned const)
     {
         ar & BOOST_SERIALIZATION_NVP(n_);
     }

     friend bool operator==(MyPrimitiveType const &l, MyPrimitiveType const
 &r)
     {
         return l.n_ == r.n_;
     }
 };

 BOOST_CLASS_IMPLEMENTATION(MyPrimitiveType,
 boost::serialization::primitive_type)


 int main( int /* argc */, char* /* argv */[] )
 {
     using namespace boost::archive;

 #if 1
     typedef polymorphic_binary_oarchive oarch;
     typedef polymorphic_binary_iarchive iarch;
 #else
     typedef binary_oarchive oarch;
     typedef binary_iarchive iarch;
 #endif

     std::stringstream stream;

     MyPrimitiveType pt;
     pt.n_ = 99;

     MyPrimitiveType pt2;
     pt2.n_ = 0;

     // save
     {
         oarch oa(stream);

         oa << BOOST_SERIALIZATION_NVP(pt);
     }

     // load
     {
         iarch ia(stream);

         ia >> BOOST_SERIALIZATION_NVP(pt2);
     }

     assert(pt == pt2);
 }

 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/5679#comment:1>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:07 UTC