I was thinking about how to solve this problem with placement new, and I faced a problem.
Suppose, that I allocate a float
array:
float *f = new float[10];
Then, I use this storage to store double
s (note that I assume that f
is properly aligned, and sizeof(float)*2==sizeof(double)
), which destroys the float array:
double *d = new(f) double;
for (int i=1; i<5; i++) {
new(d+i) double;
}
Now, is there a way to recreate the float array? The most intuitive solution
f = new(f) float[10];
may not work, as new[]
can have a space overhead, so float[10]
may not fit into f
.