Skip to content

Instantly share code, notes, and snippets.

@Akaame
Created July 4, 2021 12:09
Show Gist options
  • Save Akaame/ba9bd680d94b30c48c9a79fd7158b23e to your computer and use it in GitHub Desktop.
Save Akaame/ba9bd680d94b30c48c9a79fd7158b23e to your computer and use it in GitHub Desktop.
namespace boost {
namespace archive {
template<typename Archive, typename Rep, typename Period>
void load(Archive& ar, std::chrono::duration<Rep, Period> dur, const unsigned int version) {
int64_t duration;
ar >> duration;
dur = std::chrono::duration<Rep, Period>(duration);
}
template<typename Archive, typename Rep, typename Period>
void save(Archive& ar, std::chrono::duration<Rep, Period> dur, const unsigned int version) {
auto duration = std::chrono::duration_cast<std::chrono::milliseconds, Rep, Period>(dur).count();
ar << duration;
}
template<typename Archive, typename Rep, typename Period>
inline void serialize(Archive& ar, std::chrono::duration<Rep, Period>& dur, const unsigned int version) {
boost::serialization::split_free(ar, dur, version);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment