mirror of
https://github.com/rwengine/openrw.git
synced 2024-10-05 00:27:30 +02:00
17 lines
407 B
C++
17 lines
407 B
C++
|
#ifndef _LIBRW_BIT_CAST_CPP_
|
||
|
#define _LIBRW_BIT_CAST_CPP_
|
||
|
|
||
|
//Based on https://gist.github.com/socantre/3472964
|
||
|
#include <cstring> // memcpy
|
||
|
#include <type_traits> // is_trivially_copyable
|
||
|
#include "rw/defines.hpp" // RW_ASSERT
|
||
|
|
||
|
template <class Dest, class Source>
|
||
|
inline Dest bit_cast(Source const &source) {
|
||
|
Dest dest = Dest{};
|
||
|
std::memcpy(&dest, &source, sizeof(Dest));
|
||
|
return dest;
|
||
|
}
|
||
|
|
||
|
#endif
|