Fix issue #44 - example to dump TriviallyCopyable types doesn't work any

more
This commit is contained in:
greg7mdp
2022-08-12 20:24:24 -04:00
parent d62b8472a3
commit ca9f02fda3
2 changed files with 32 additions and 6 deletions
+26
View File
@@ -158,6 +158,19 @@ public:
return true;
}
template<typename V>
typename std::enable_if<type_traits_internal::IsTriviallyCopyable<V>::value, bool>::type
saveBinary(const V& v) {
ofs_.write(reinterpret_cast<const char *>(&v), sizeof(V));
return true;
}
template<typename Map>
auto saveBinary(const Map& v) -> decltype(v.phmap_dump(*this), bool())
{
return v.phmap_dump(*this);
}
private:
std::ofstream ofs_;
};
@@ -174,6 +187,19 @@ public:
return true;
}
template<typename V>
typename std::enable_if<type_traits_internal::IsTriviallyCopyable<V>::value, bool>::type
loadBinary(V* v) {
ifs_.read(reinterpret_cast<char *>(v), sizeof(V));
return true;
}
template<typename Map>
auto loadBinary(Map* v) -> decltype(v->phmap_load(*this), bool())
{
return v->phmap_load(*this);
}
private:
std::ifstream ifs_;
};