In Qt, QByteArray can loosely be viewed as an implementation/wrapper for charconst *, what is your own implementation of ByteArray? Why would you want to convert ANY type to a byteArray? Perhaps your only solution might not be the only one after all
I have just learned C++ and I am trying to give myself something to do so I decided to try make something that encrypts bytes of values to make it more difficult for other people to read the process memory ^~^
We can examine objects of any type as arrays of bytes.
However, to be able to restore the value from an array of bytes:
Objects of trivially-copyable types are the only C++ objects that may be safely copied with std::memcpy or serialized to/from binary files with std::ofstream::write()/std::ifstream::read(). In general, a trivially copyable type is any type for which the underlying bytes can be copied to an array of char or unsigned char and into a new object of the same type, and the resulting object would have the same value as the original. http://en.cppreference.com/w/cpp/types/is_trivially_copyable
It creates a type alias; byte becomes another name for the type unsigned char. std::array< byte, sizeof(T) > is a wee bit easier on the eye than std::array< unsigned char, sizeof(T) >.
Though both mean the the same thing.