mirror of
https://github.com/greg7mdp/parallel-hashmap.git
synced 2026-08-29 08:34:39 +08:00
support older version cpp compiler to use is_trivially_copyable
This commit is contained in:
Vendored
+12
-3
@@ -82,12 +82,21 @@ struct PairTrait<std::pair<T1, T2>>: public std::true_type {
|
||||
using second_type = T2;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
#if defined(__GLIBCXX__) && __GLIBCXX__ < 20150801
|
||||
struct IsTriviallyCopyable : public std::integral_constant<bool, __has_trivial_copy(T)> {
|
||||
};
|
||||
#else
|
||||
struct IsTriviallyCopyable : public std::is_trivially_copyable<T> {
|
||||
};
|
||||
#endif
|
||||
|
||||
template<typename V>
|
||||
struct IsDumpableType {
|
||||
static constexpr bool value = std::is_trivially_copyable<V>::value
|
||||
static constexpr bool value = IsTriviallyCopyable<V>::value
|
||||
|| (PairTrait<V>::value
|
||||
&& std::is_trivially_copyable<typename PairTrait<V>::first_type>::value
|
||||
&& std::is_trivially_copyable<typename PairTrait<V>::second_type>::value);
|
||||
&& IsTriviallyCopyable<typename PairTrait<V>::first_type>::value
|
||||
&& IsTriviallyCopyable<typename PairTrait<V>::second_type>::value);
|
||||
};
|
||||
|
||||
template <typename... Ts>
|
||||
|
||||
Vendored
+3
-23
@@ -326,7 +326,7 @@ public:
|
||||
~ArchiveGuard() {
|
||||
if (ar_) {
|
||||
ar_->finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
private:
|
||||
Archive* ar_;
|
||||
@@ -351,23 +351,13 @@ public:
|
||||
}
|
||||
|
||||
template<typename V>
|
||||
typename std::enable_if<std::is_trivially_copyable<V>::value, bool>::type
|
||||
typename std::enable_if<type_traits_internal::IsTriviallyCopyable<V>::value, bool>::type
|
||||
dump(const V& v) {
|
||||
CHECK_FILE(ofs_);
|
||||
ofs_.write(reinterpret_cast<char*>(const_cast<V*>(&v)), sizeof(V));
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename V>
|
||||
typename std::enable_if<type_traits_internal::PairTrait<V>::value
|
||||
&& type_traits_internal::IsDumpableType<V>::value, bool>::type
|
||||
dump(const V& v) {
|
||||
using first_type = typename type_traits_internal::PairTrait<V>::first_type;
|
||||
using second_type = typename type_traits_internal::PairTrait<V>::second_type;
|
||||
return dump<first_type>(v.first)
|
||||
&& dump<second_type>(v.second);
|
||||
}
|
||||
|
||||
void finish() {
|
||||
if (ofs_.is_open()) {
|
||||
ofs_.close();
|
||||
@@ -397,23 +387,13 @@ public:
|
||||
}
|
||||
|
||||
template<typename V>
|
||||
typename std::enable_if<std::is_trivially_copyable<V>::value, bool>::type
|
||||
typename std::enable_if<type_traits_internal::IsTriviallyCopyable<V>::value, bool>::type
|
||||
load(V* v) {
|
||||
CHECK_FILE(ifs_);
|
||||
ifs_.read(reinterpret_cast<char*>(v), sizeof(V));
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename V>
|
||||
typename std::enable_if<type_traits_internal::PairTrait<V>::value
|
||||
&& type_traits_internal::IsDumpableType<V>::value, bool>::type
|
||||
load(V* v) {
|
||||
using first_type = typename std::remove_cv<typename type_traits_internal::PairTrait<V>::first_type>::type;
|
||||
using second_type = typename std::remove_cv<typename type_traits_internal::PairTrait<V>::second_type>::type;
|
||||
return load<first_type>(const_cast<first_type*>(&v->first))
|
||||
&& load<second_type>(const_cast<second_type*>(&v->second));
|
||||
}
|
||||
|
||||
void finish() {
|
||||
if (ifs_.is_open()) {
|
||||
ifs_.close();
|
||||
|
||||
Reference in New Issue
Block a user