Last active
September 5, 2019 12:02
-
-
Save TheEyesightDim/e7dc0d8921cb27071dbce53dcccb1fe7 to your computer and use it in GitHub Desktop.
Converts some type into its representation as a byte array.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <array> | |
template <typename T> | |
constexpr std::array<char, sizeof(T)> into_bytes(const T& t){ | |
std::array<char, sizeof(T)> bytes; | |
std::copy( reinterpret_cast<const char*>(&t), reinterpret_cast<const char*>(&t) + sizeof(t), bytes.begin() ); | |
return bytes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment