Boost C++ Libraries: Ticket #2271: Cannot load version 1.35.0 xml archives that contain vectors of primitive types https://svn.boost.org/trac10/ticket/2271 <p> Version 1.35.0 xml archives are missing the &lt;item_version&gt; element in vectors of primitive types. </p> <p> This is obviously a known issue, because version 1.36.0 includes the compatibility header vector_135.hpp. </p> <p> The problem is, that even when vector_135.hpp is included, it makes no difference because the appropriate load method is not called. </p> <p> The load method in vector.hpp that is aware of the 1.35.0 bug is this: </p> <pre class="wiki">template&lt;class Archive, class U, class Allocator&gt; inline void load( Archive &amp; ar, std::vector&lt;U, Allocator&gt; &amp;t, const unsigned int /* file_version */, mpl::true_ ){ collection_size_type count(t.size()); ar &gt;&gt; BOOST_SERIALIZATION_NVP(count); t.resize(count); unsigned int item_version=0; if(BOOST_SERIALIZATION_VECTOR_VERSION &lt; ar.get_library_version()) ar &gt;&gt; BOOST_SERIALIZATION_NVP(item_version); if (!t.empty()) ar &gt;&gt; make_array(detail::get_data(t),t.size()); } </pre><p> It works correctly, when called. The problem is that the load method which dispatches to either the default or the optimized version chooses the wrong version for vectors of primitive types. </p> <pre class="wiki">template&lt;class Archive, class U, class Allocator&gt; inline void load( Archive &amp; ar, std::vector&lt;U, Allocator&gt; &amp;t, const unsigned int file_version ){ load(ar,t,file_version, BOOST_DEDUCED_TYPENAME use_array_optimization&lt;Archive&gt;::template apply&lt;U&gt;::type() ); } </pre><p> For some reason, use_array_optimization does not work with primitive types. </p> <p> Version 1.35.0 used boost::detail::has_default_constructor&lt;U&gt;() to dispatch. </p> <p> My patch changes the dispatching load method to this: </p> <pre class="wiki">template&lt;class Archive, class U, class Allocator&gt; inline void load( Archive &amp; ar, std::vector&lt;U, Allocator&gt; &amp;t, const unsigned int file_version ){ if(BOOST_SERIALIZATION_VECTOR_VERSION &lt; ar.get_library_version()) { load(ar,t,file_version, BOOST_DEDUCED_TYPENAME use_array_optimization&lt;Archive&gt;::template apply&lt;U&gt;::type() ); } else { load(ar,t,file_version, boost::detail::has_default_constructor&lt;U&gt;() ); } } </pre><p> It works well, but I do not fully why use_array_optimization did not work alone. </p> <p> I used a vector&lt; unsigned char &gt; as a test case. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2271 Trac 1.4.3 Ryan Mulder <rjmyst3@…> Fri, 29 Aug 2008 15:34:06 GMT attachment set https://svn.boost.org/trac10/ticket/2271 https://svn.boost.org/trac10/ticket/2271 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">load_1.35_vector.patch</span> </li> </ul> Ticket Robert Ramey Mon, 01 Sep 2008 06:23:46 GMT owner changed https://svn.boost.org/trac10/ticket/2271#comment:1 https://svn.boost.org/trac10/ticket/2271#comment:1 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Robert Ramey</span> to <span class="trac-author">Matthias Troyer</span> </li> </ul> Ticket anonymous Tue, 04 Aug 2009 19:54:59 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/2271#comment:2 https://svn.boost.org/trac10/ticket/2271#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">fixed</span> </li> </ul> Ticket Matthias Troyer Tue, 04 Aug 2009 23:00:12 GMT <link>https://svn.boost.org/trac10/ticket/2271#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2271#comment:3</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/55415" title="Fixed ticket 2271">[55415]</a>) Fixed ticket 2271 </p> </description> <category>Ticket</category> </item> </channel> </rss>