Boost C++ Libraries: Ticket #13478: multi_index_container serialization of non copyable types https://svn.boost.org/trac10/ticket/13478 <p> A multi_index container holding non-copyable types fails to serialize because of delayed insertion through <code>std::pair&lt;node_type*,bool&gt; insert_(const Value&amp; v,Variant variant)</code> in multi_index_container.hpp:555 happening in <code>void load(Archive&amp; ar,const unsigned int version)</code> in multi_index_container.hpp:940 </p> <p> The insertion should use a rvalue reference overload moving the previously loaded value. </p> <p> Minimal example: </p> <pre class="wiki">template&lt;class Archive&gt; void check_serialize(Archive &amp;ar) { using non_copyable_type = std::unique_ptr&lt;int&gt;; using non_copyable_multi_index = boost::multi_index_container &lt; non_copyable_type , boost::multi_index::indexed_by &lt; boost::multi_index::hashed_unique &lt; boost::multi_index::const_mem_fun &lt; non_copyable_type , typename non_copyable_type::pointer , &amp;non_copyable_type::get &gt; &gt; &gt; &gt;; non_copyable_multi_index mu; // fine if constexpr (Archive::is_saving::value) ar &lt;&lt; boost::serialization::make_nvp("mu",mu); // fine else ar &gt;&gt; boost::serialization::make_nvp("mu",mu); // error } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/13478 Trac 1.4.3 Sébastien Paris <sebastien.paris@…> Tue, 13 Mar 2018 09:23:39 GMT <link>https://svn.boost.org/trac10/ticket/13478#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13478#comment:1</guid> <description> <p> Proposed resolution: modify multi_index_container.hpp:954-955 from </p> <pre class="wiki"> std::pair&lt;node_type*,bool&gt; p=insert_( value.get(),super::end().get_node()); </pre><p> to </p> <pre class="wiki"> std::pair&lt;node_type*,bool&gt; p=insert_( value.get(),super::end().get_node(),detail::rvalue_tag()); </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>Joaquín M López Muñoz</dc:creator> <pubDate>Tue, 13 Mar 2018 09:34:28 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13478#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13478#comment:2</guid> <description> <p> Hi Sébastien, </p> <p> Thank you for the bug report. Also, your proposed fix is correct. </p> <p> It's going to take me a couple of days till I find the time to change this in develop. As we're now closing Boost 1.67, the change will go in Boost 1.68. </p> <p> Best regards, </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Joaquín M López Muñoz</dc:creator> <pubDate>Wed, 14 Mar 2018 20:10:40 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/13478#comment:3 https://svn.boost.org/trac10/ticket/13478#comment:3 <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> <p> Fixed at: </p> <p> <a class="ext-link" href="https://github.com/boostorg/multi_index/commit/4d21e8962151d7d6852c5bc861a2f09fed060be5"><span class="icon">​</span>https://github.com/boostorg/multi_index/commit/4d21e8962151d7d6852c5bc861a2f09fed060be5</a> </p> Ticket