I don’t understand why a vector‘s iterator should be invalidated when a reallocation happens.
Couldn’t this have been prevented simply by storing an offset — instead of a pointer — in the iterator?
Why was vector not designed this way?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Just to add a citation to the performance-related justification: when designing C++, Stroustrup thought it was vital that template classes like std::vector approach the performance characteristics of native arrays:
Bjarne Stroustrup, Design and Evolution of C++, p.342.