[mlpack-git] [mlpack/mlpack] Serialize a class with "map<int, Node*>" (#811)
notifications at github.com
Mon Nov 14 10:15:20 EST 2016
Hi there, sorry for the slow response. This is a tricky issue...
mlpack 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<T>` object if `T::Serialize()` exists, and this `FirstShim<T>` type then does the necessary wrangling to make the whole thing work.
So 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<>` uses `BOOST_SERIALIZATION_NVP()`, so a map that holds any type with `Serialize()` cannot be serialized using the `std::map<>::serialize()` implementation.
This means that there are two choices: manually implement `std::map<>::serialize()` (i.e. don't call `ar & data::CreateNVP(root, "root")` but instead do the implementation by hand), or rename your `Serialize()` function to `serialize()` and it should all work.
Sorry for the long explanation---the topic is complex. :) I hope this helps, and if I can clarify anything, let me know.
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the mlpack-git