I know that std::vector<T>
internally stores it's data contiguously (unless it is std::vector<bool>
) both in the old C++03
standard and the new C++11
.
Nice stackoverflow questions that deal with this and quote the standard: answer, answer.
What about the data inside nested vectors std::vector <std::vector <T> >
? How is that stored?
If every internal vector needs to store it's data contiguously, how can it be true that &v[n] == &v[0] + n for all 0 <= n < v.size()
.
To phrase this slightly different, is it possible to access all the elements stored in such nested structure "simply" and sequentially (via a pointer or similar) the same way it can be done for a 1-D vector?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…