That depends how much of the semantics you want to preserve. The first step would be
std::vector<object> array[3];
Now we have a (effectively) a 3 element array of variable size storage.
We could also wrap a std::vector<object>
maintain three sizes and provide access to a slice of the vector
. Insertions into one of the subvectors now become rather expensive because possibly a lot of data has to be copied around, something the std::vector<object> array[3]
version avoids. Iterator invalidation properties would also be stricter.
It depends on what you want to do. If you are going to repeatedly emplace_back
on either of the three vector
use the first version, if you fill them in order, don't erase elements, the last version provides marginal benefits.