<p>Hi there, sorry for the slow response.  This is a tricky issue...</p>

<p>mlpack uses template metaprogramming in <code>src/mlpack/core/data/serialization_shim.hpp</code> so that you can write a method with <code>Serialize()</code> instead of <code>serialize()</code> which meshes with the style guide (member functions should start with a capital letter).  The details of how this is done is that the <code>data::CreateNVP()</code> function essentially wraps the given type <code>T</code> in a <code>FirstShim&lt;T&gt;</code> object if <code>T::Serialize()</code> exists, and this <code>FirstShim&lt;T&gt;</code> type then does the necessary wrangling to make the whole thing work.</p>

<p>So this means that for any class that has <code>Serialize()</code>, for it to be properly serialized, then <code>data::CreateNVP()</code> must be called to serialize it, and not <code>BOOST_SERIALIZATION_NVP()</code>.  But the serialization code for <code>std::map&lt;&gt;</code> uses <code>BOOST_SERIALIZATION_NVP()</code>, so a map that holds any type with <code>Serialize()</code> cannot be serialized using the <code>std::map&lt;&gt;::serialize()</code> implementation.</p>

<p>This means that there are two choices: manually implement <code>std::map&lt;&gt;::serialize()</code> (i.e. don't call <code>ar &amp; data::CreateNVP(root, "root")</code> but instead do the implementation by hand), or rename your <code>Serialize()</code> function to <code>serialize()</code> and it should all work.</p>

<p>Sorry for the long explanation---the topic is complex. :)  I hope this helps, and if I can clarify anything, let me know.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">&mdash;<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/mlpack/mlpack/issues/811#issuecomment-260362172">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AJ4bFCIQtUOso9wkI_VouOGCiuRyvmqqks5q-HsIgaJpZM4Kwpgr">mute the thread</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AJ4bFMuTSDZ9yk9V7C2XXG-79GYtYitwks5q-HsIgaJpZM4Kwpgr.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/mlpack/mlpack/issues/811#issuecomment-260362172"></link>
  <meta itemprop="name" content="View Issue"></meta>
</div>
<meta itemprop="description" content="View this Issue on GitHub"></meta>
</div>

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/mlpack/mlpack","title":"mlpack/mlpack","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/mlpack/mlpack"}},"updates":{"snippets":[{"icon":"PERSON","message":"@rcurtin in #811: Hi there, sorry for the slow response.  This is a tricky issue...\r\n\r\nmlpack uses template metaprogramming in `src/mlpack/core/data/serialization_shim.hpp` so that you can write a method with `Serialize()` instead of `serialize()` which meshes with the style guide (member functions should start with a capital letter).  The details of how this is done is that the `data::CreateNVP()` function essentially wraps the given type `T` in a `FirstShim\u003cT\u003e` object if `T::Serialize()` exists, and this `FirstShim\u003cT\u003e` type then does the necessary wrangling to make the whole thing work.\r\n\r\nSo this means that for any class that has `Serialize()`, for it to be properly serialized, then `data::CreateNVP()` must be called to serialize it, and not `BOOST_SERIALIZATION_NVP()`.  But the serialization code for `std::map\u003c\u003e` uses `BOOST_SERIALIZATION_NVP()`, so a map that holds any type with `Serialize()` cannot be serialized using the `std::map\u003c\u003e::serialize()` implementation.\r\n\r\nThis means that there are two choices: manually implement `std::map\u003c\u003e::serialize()` (i.e. don't call `ar \u0026 data::CreateNVP(root, \"root\")` but instead do the implementation by hand), or rename your `Serialize()` function to `serialize()` and it should all work.\r\n\r\nSorry for the long explanation---the topic is complex. :)  I hope this helps, and if I can clarify anything, let me know."}],"action":{"name":"View Issue","url":"https://github.com/mlpack/mlpack/issues/811#issuecomment-260362172"}}}</script>