1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-02 23:21:15 +03:00

Add some safety static_asserts to remote read/write functions

This commit is contained in:
Maxime Coste 2018-04-07 12:32:31 +10:00
parent 4ff0c58518
commit 23853f499e

View File

@ -67,6 +67,7 @@ public:
template<typename T>
void write(const T& val)
{
static_assert(std::is_trivially_copyable<T>::value, "");
write((const char*)&val, sizeof(val));
}
@ -196,15 +197,10 @@ public:
template<typename T>
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<T>::value, "");
T res;
read(reinterpret_cast<char*>(&res), sizeof(T));
return res;
}
template<typename T>