How do I serialize std::chrono::minutes with chrono?
I tried this
struct A {
std::chrono::minutes m;
template <class Archive>
void serialize(Archive& ar) {
ar(m);
}
};
int main()
{
A a;
std::ostringstream os;
cereal::JSONOutputArchive ar1(os);
ar1(cereal::make_nvp("A", a));
A result;
std::istringstream is(os.str());
cereal::JSONInputArchive ar2(is);
ar2(cereal::make_nvp("A", result));
if (a.m != result.m)
std::cout << "error\n";
}
but get an error in Visual Studio 2015
1> Types must either have a serialize function, load/save pair, or load_minimal/save_minimal pair (you may not mix these).
1> Serialize functions generally have the following signature:
1>
1> template<class Archive>
1> void serialize(Archive & ar)
1> {
1> ar( member1, member2, member3 );
1> }
1>
1>
1> cereal.hpp(702): note: see reference to function template instantiation 'ArchiveType &cereal::InputArchive<ArchiveType,0>::processImpl<std::chrono::minutes,0>(const T &)' being compiled
1> with
1> [
1> ArchiveType=cereal::JSONInputArchive,
1> T=std::chrono::minutes
1> ]
Ideally I wan to serialize and deserialize in a portable way.
Aucun commentaire:
Enregistrer un commentaire