c++11 - C++ Cereal Archive Type Specialization not working -
i'm using cereal 1.1.2 vs 2013.
i've tried example archive specialization types here: http://uscilab.github.io/cereal/archive_specialization.html
but doesn't compile error:
error c2665: 'cereal::make_nvp' : none of 3 overloads convert argument types ... while trying match argument list '(const std::string, const std::string)
i'm trying compile following code, using snippets example:
#include "cereal\types\map.hpp" namespace cereal { //! saving std::map<std::string, std::string> text based archives // note shows off internal cereal traits such enableif, // allow template instantiated if predicates // true template <class archive, class c, class a, traits::enableif<traits::is_text_archive<archive>::value> = traits::sfinae> inline void save(archive & ar, std::map<std::string, std::string, c, a> const & map) { (const auto & : map) ar(cereal::make_nvp<archive>(i.first, i.second)); } //! loading std::map<std::string, std::string> text based archives template <class archive, class c, class a, traits::enableif<traits::is_text_archive<archive>::value> = traits::sfinae> inline void load(archive & ar, std::map<std::string, std::string, c, a> & map) { map.clear(); auto hint = map.begin(); while (true) { const auto nameptr = ar.getnodename(); if (!nameptr) break; std::string key = nameptr; std::string value; ar(value); hint = map.emplace_hint(hint, std::move(key), std::move(value)); } } } // namespace cereal #include "cereal\archives\json.hpp" #include <iostream> #include <string> #include <fstream> int main() { std::stringstream ss; { cereal::jsonoutputarchive ar(ss); std::map<std::string, std::string> filter = { { "type", "sensor" }, { "status", "critical" } }; ar(cereal_nvp(filter)); } std::cout << ss.str() << std::endl; { cereal::jsoninputarchive ar(ss); cereal::jsonoutputarchive ar2(std::cout); std::map<std::string, std::string> filter; ar(cereal_nvp(filter)); ar2(cereal_nvp(filter)); } std::cout << std::endl; return 0; }
note if remove save() function overload compile. goal able use map key json key, comes out this:
{ "map": { "a": 1, "b": 2 }, "map_not_string": [ { "key": 1, "value": 1 }, { "key": 2, "value": 2 } ] }
i brought question issue on cereal's github , got answer: https://github.com/uscilab/cereal/issues/197
the problem templated version of make_nvp, so
ar(cereal::make_nvp<archive>(i.first, i.second));
becomes
ar(cereal::make_nvp(i.first, i.second));
the documentation updated shouldn't problem anymore.
Comments
Post a Comment