Is this safe or does this just happen to work on my current compiler? Is there anything about this in the standard? The result in the floats vector is correct.
class Color { public: Color(float r, float g, float b, float a) : mColor{r,g,b,a} {}; inline const float *data() const { return mColor; } private: enum {vectorSize = 4}; float mColor[vectorSize]; }; //test std::vector<Color> colors(2); std::vector<float> floats(8); colors[0] = Color(0.1, 0.2, 0.3, 0.4); colors[1] = Color(0.5, 0.6, 0.7, 0.8); memcpy(floats.data(), colors.data(), 8 * sizeof(float));
std::copyorstd::copy_n