diff --git a/src/remote.cc b/src/remote.cc index b851474f..f3a90d62 100644 --- a/src/remote.cc +++ b/src/remote.cc @@ -67,6 +67,7 @@ public: template void write(const T& val) { + static_assert(std::is_trivially_copyable::value, ""); write((const char*)&val, sizeof(val)); } @@ -196,15 +197,10 @@ public: template T read() { - union U - { - T object; - alignas(T) char data[sizeof(T)]; - U() {} - ~U() { object.~T(); } - } u; - read(u.data, sizeof(T)); - return u.object; + static_assert(std::is_trivially_copyable::value, ""); + T res; + read(reinterpret_cast(&res), sizeof(T)); + return res; } template