添加speci在序列化類聲明點之前std :: chrono :: time的alization可能會有所幫助。必須的boost ::系列化命名空間中聲明使用的
namespace boost {
namespace archive {
namespace chrn = std::chrono;
template<class Archive, typename clock>
void load(Archive& ar, chrn::time_point<clock>& tp, unsigned)
{
chrn::milliseconds::rep millis;
ar & millis;
tp = chrn::time_point<clock>(chrn::milliseconds(millis));
}
template<class Archive, typename clock>
void save(Archive& ar, chrn::time_point<clock> const& tp, unsigned)
{
chrn::milliseconds::rep millis = chrn::duration_cast<chrn::milliseconds>(tp.time_since_epoch()).count();
ar & millis;
}
template<class Archive, typename clock>
inline void serialize(Archive & ar, std::chrono::time_point<clock>& tp, unsigned version)
{
boost::serialization::split_free(ar, tp, version);
}
}
}
例子:
std::chrono::system_clock::time_point installation_point;
std::chrono::system_clock::time_point trial_end_point;
/// @brief Obligatory method for any serializable object
template<class Archive>
void serialize(Archive & ar, const unsigned int version) {
ar & BOOST_SERIALIZATION_NVP(installation_point);
ar & BOOST_SERIALIZATION_NVP(trial_end_point);
}