Hi!
Suppose I reserve(X) for a std::vector. Is there a natural way to get an Iterator pointing to the end of its capacity? So that e.g. I can fill up all the elements with a for loop:
std::vector<int> Myvect;
std::vector<int>::iterator Iter;
Myvect.reserve(30);
for (Iter=Myvect.begin(); Iter!=/*THE ITERATOR TO THE END OF CAPACITY;Iter++)
std::cin>>*Iter
I understad that I can get Iterators for the end of the SIZE through Myvect.end(). But I cant find a solution for this problem.
Your example would cause undefined behavior. You can't write to memory locations past the size() of the vector, even you already reserved that much capacity.
Of course, you might want to make sure capacity isn't already bigger than what you're reserving or this might have some unexpected results, depending on how you're using it.
From my perspective, something like the following would probably be more useful (and safe.)