I am aware that the standard declares that std::tuple
is not trivially copiable so std::memcpy
will have an undefined behavior on this type, but are there infos (maybe something compiler specific) to safely memcpy std::tuple
with basic types (int
, float
)?
A possible example:
auto my_computation = [](...){ something...; return std::make_tuple(...) }
auto ret = my_computation(...);
unsigned char buf[...];
memcpy(buf, &ret, sizoof(ret));
//send the bytes out to another device
I have had no issues (for now) with this raw memcpy but I am not sure if it is reliable (g++ (Alpine 10.3.1_git20210424) 10.3.1 20210424).
I can assure that the receiver architecture is compatible with this bytes representation (e.g. endianess) so this is not a problem.