c++ std::pair, std::vector & memcopy
c++, memcpy, std-pair, vector
Solution
No, a class containing `T1` and `T2` is not guaranteed the same layout or alignment as `std::pair<T1, T2>`, at least in C++98 (since `std::pair` is not a POD type). The story may be different in C++0x.
Problem
is it safe to memcopy myvect.size()*sizeof(foo) bytes from the memoryadress of the first element of a ``` std::vector<std::pair<T1, T2> > myvect ``` into an array of ``` struct foo{ T1 first; T2 second; } ``` if the array is allocated with the same number of elements as the vector's size? thanks