Boost C++ Libraries: Ticket #5679: boost::serialization::primitive_type used with polymorphic archive fails to compile https://svn.boost.org/trac10/ticket/5679 <p> Not sure if this belongs with uuid or serialization, but the uuid library has a test that passes for non-polymorphic archive types; see ".../libs/uuid/test/test_serialization.cpp". </p> <p> To trigger the problem, take the (above) test file, include some polymorphic archives, e.g. </p> <pre class="wiki">#include &lt;boost/archive/polymorphic_binary_oarchive.hpp&gt; #include &lt;boost/archive/polymorphic_binary_iarchive.hpp&gt; </pre><p> and extend main(): </p> <pre class="wiki"> test_archive&lt;polymorphic_binary_oarchive, polymorphic_binary_iarchive, ostringstream, istringstream&gt;(); </pre><p> (apologies if this is fixed post-1.44) </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5679 Trac 1.4.3 boost@… Wed, 13 Jul 2011 20:59:27 GMT version, summary changed https://svn.boost.org/trac10/ticket/5679#comment:1 https://svn.boost.org/trac10/ticket/5679#comment:1 <ul> <li><strong>version</strong> <span class="trac-field-old">Boost 1.44.0</span> → <span class="trac-field-new">Boost 1.47.0</span> </li> <li><strong>summary</strong> <span class="trac-field-old">Serialization of uuid with polymorphic archive fails to compile</span> → <span class="trac-field-new">boost::serialization::primitive_type used with polymorphic archive fails to compile</span> </li> </ul> <p> A bit of further investigation reveals this to be an issue with using boost::serialization::primitive_type and polymorphic archive types. </p> <p> UUID just happens to be a case. </p> <p> Here's a test to demonstrate: (Note: this was tested against 1.47; the problem is still present.) </p> <pre class="wiki">#include &lt;sstream&gt; #include &lt;boost/archive/polymorphic_binary_oarchive.hpp&gt; #include &lt;boost/archive/polymorphic_binary_iarchive.hpp&gt; struct MyPrimitiveType { int n_; template &lt;typename Ar&gt; void serialize(Ar &amp;ar, unsigned const) { ar &amp; BOOST_SERIALIZATION_NVP(n_); } friend bool operator==(MyPrimitiveType const &amp;l, MyPrimitiveType const &amp;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 &lt;&lt; BOOST_SERIALIZATION_NVP(pt); } // load { iarch ia(stream); ia &gt;&gt; BOOST_SERIALIZATION_NVP(pt2); } assert(pt == pt2); } </pre> Ticket Robert Ramey Sun, 31 Jul 2011 17:44:43 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/5679#comment:2 https://svn.boost.org/trac10/ticket/5679#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> I don't think it is possible to fix this. </p> <p> Here is the short explanation of the polymorphic archive concept. </p> <p> a) One compiles his serialization implementations against the polymorphic_oarchive class. This means that your classes will be saved to any kind of output archive with out instantiating any new code. This applies for all future and past output archive classes. </p> <p> b) marking a type as "primitive" indicates that the code for doing the serialization is to be found in the set of functions which are compiled in the .._oprimitive.hpp file. </p> <p> c) If one would add now "primitive" types to a polymorphic archive - this would totally defeat the original goal of the polymorphic archive. </p> <p> In a nutshell - instantiating code for your own class at the ..._oprimitive level is incompatiable with the polymorphic oarchive idea that we can use the already made archives without doing any new instantiation. </p> <p> I realize that this is not at all clear in the explanation of the polymorphic archives. When I first looked at your code I thought it was a bug. It was only after an hour (or more!) of experimentation that I came to this understanding. </p> <p> Thanks for taking the time to prepare your test case. I'll put a little bit of the explanation in the documentation. </p> <p> Robert Ramey </p> Ticket boost@… Wed, 03 Aug 2011 21:02:31 GMT <link>https://svn.boost.org/trac10/ticket/5679#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5679#comment:3</guid> <description> <p> Well, okay, that seems fair enough. However, where does that leave boost::uuid? - it was the serialization of this type that originally tripped me up. </p> <p> Was it incorrect for uuid to have used boost::serialization::primitive_type? Should this issue be transferred to that library? </p> <p> As it stands, uuid can not be serialized to a polymorphic archive. </p> </description> <category>Ticket</category> </item> <item> <author>rodolfo@…</author> <pubDate>Tue, 26 Jun 2012 17:23:58 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5679#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5679#comment:4</guid> <description> <p> Hi, I'm using boost-1_49 and got stuck by this "bug". One solution, at least for streamable types, might be a template overload of polymorphic_oarchive_impl::save that converts the value to a string, then dispatches it to save(const std::string *). </p> <p> How about it? </p> </description> <category>Ticket</category> </item> </channel> </rss>