Cleanup std::is_pod usage (deprecated in C++20)

This commit is contained in:
Nekotekina 2020-03-18 18:27:43 +03:00
parent 6a2571d0e1
commit aa5c6c4d2b
2 changed files with 18 additions and 18 deletions

View File

@ -290,16 +290,16 @@ namespace fs
} }
// Write POD unconditionally // Write POD unconditionally
template<typename T> template <typename T>
std::enable_if_t<std::is_pod<T>::value && !std::is_pointer<T>::value, const file&> write(const T& data) const std::enable_if_t<std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>, const file&> write(const T& data) const
{ {
if (write(std::addressof(data), sizeof(T)) != sizeof(T)) xfail(); if (write(std::addressof(data), sizeof(T)) != sizeof(T)) xfail();
return *this; return *this;
} }
// Write POD std::vector unconditionally // Write POD std::vector unconditionally
template<typename T> template <typename T>
std::enable_if_t<std::is_pod<T>::value && !std::is_pointer<T>::value, const file&> write(const std::vector<T>& vec) const std::enable_if_t<std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>, const file&> write(const std::vector<T>& vec) const
{ {
if (write(vec.data(), vec.size() * sizeof(T)) != vec.size() * sizeof(T)) xfail(); if (write(vec.data(), vec.size() * sizeof(T)) != vec.size() * sizeof(T)) xfail();
return *this; return *this;
@ -319,30 +319,30 @@ namespace fs
} }
// Read POD, sizeof(T) is used // Read POD, sizeof(T) is used
template<typename T> template <typename T>
std::enable_if_t<std::is_pod<T>::value && !std::is_pointer<T>::value, bool> read(T& data) const std::enable_if_t<std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>, bool> read(T& data) const
{ {
return read(&data, sizeof(T)) == sizeof(T); return read(&data, sizeof(T)) == sizeof(T);
} }
// Read POD std::vector, size must be set by resize() method // Read POD std::vector, size must be set by resize() method
template<typename T> template <typename T>
std::enable_if_t<std::is_pod<T>::value && !std::is_pointer<T>::value, bool> read(std::vector<T>& vec) const std::enable_if_t<std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>, bool> read(std::vector<T>& vec) const
{ {
return read(vec.data(), sizeof(T) * vec.size()) == sizeof(T) * vec.size(); return read(vec.data(), sizeof(T) * vec.size()) == sizeof(T) * vec.size();
} }
// Read POD std::vector // Read POD std::vector
template<typename T> template <typename T>
std::enable_if_t<std::is_pod<T>::value && !std::is_pointer<T>::value, bool> read(std::vector<T>& vec, std::size_t size) const std::enable_if_t<std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>, bool> read(std::vector<T>& vec, std::size_t size) const
{ {
vec.resize(size); vec.resize(size);
return read(vec.data(), sizeof(T) * size) == sizeof(T) * size; return read(vec.data(), sizeof(T) * size) == sizeof(T) * size;
} }
// Read POD (experimental) // Read POD (experimental)
template<typename T> template <typename T>
std::enable_if_t<std::is_pod<T>::value && !std::is_pointer<T>::value, T> read() const std::enable_if_t<std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>, T> read() const
{ {
T result; T result;
if (!read(result)) xfail(); if (!read(result)) xfail();
@ -360,7 +360,7 @@ namespace fs
// Read full file to std::vector // Read full file to std::vector
template<typename T> template<typename T>
std::enable_if_t<std::is_pod<T>::value && !std::is_pointer<T>::value, std::vector<T>> to_vector() const std::enable_if_t<std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>, std::vector<T>> to_vector() const
{ {
std::vector<T> result; std::vector<T> result;
result.resize(size() / sizeof(T)); result.resize(size() / sizeof(T));

View File

@ -822,19 +822,19 @@ struct alignas(A) any_pod
any_pod() = default; any_pod() = default;
template <typename T, typename T2 = TT<T>, typename = std::enable_if_t<std::is_pod<T2>::value && sizeof(T2) == S && alignof(T2) <= A>> template <typename T, typename T2 = TT<T>, typename = std::enable_if_t<std::is_trivially_copyable_v<T> && sizeof(T2) == S && alignof(T2) <= A>>
any_pod(const T& value) any_pod(const T& value)
{ {
reinterpret_cast<T2&>(data) = value; *this = std::bit_cast<any_pod>(value);
} }
template <typename T, typename T2 = TT<T>, typename = std::enable_if_t<std::is_pod<T2>::value && sizeof(T2) == S && alignof(T2) <= A>> template <typename T, typename T2 = TT<T>, typename = std::enable_if_t<std::is_trivially_copyable_v<T> && sizeof(T2) == S && alignof(T2) <= A>>
T2& as() T2& as()
{ {
return reinterpret_cast<T2&>(data); return reinterpret_cast<T2&>(data);
} }
template <typename T, typename T2 = TT<T>, typename = std::enable_if_t<std::is_pod<T2>::value && sizeof(T2) == S && alignof(T2) <= A>> template <typename T, typename T2 = TT<T>, typename = std::enable_if_t<std::is_trivially_copyable_v<T> && sizeof(T2) == S && alignof(T2) <= A>>
const T2& as() const const T2& as() const
{ {
return reinterpret_cast<const T2&>(data); return reinterpret_cast<const T2&>(data);
@ -899,7 +899,7 @@ struct cmd64 : any64
} }
}; };
static_assert(sizeof(cmd64) == 8 && std::is_pod<cmd64>::value, "Incorrect cmd64 type"); static_assert(sizeof(cmd64) == 8 && std::is_trivially_copyable_v<cmd64>, "Incorrect cmd64 type");
// Error code type (return type), implements error reporting. Could be a template. // Error code type (return type), implements error reporting. Could be a template.
struct error_code struct error_code