iterate in the middle

Started by
2 comments, last by Zahlman 15 years, 9 months ago
stl containers have a .begin() and .end() func. Lets say i want to iterate from index 5000 to 5025th, how would i do this? I dont need to know 5025th, i just want to start at index 5000 instead of 0 and increasing it 5000 times every time i call my iterate func. Maybe i should stick with vector and deque and use the [] feature?
<SkilletAudio> Your framerate proves your lack of manhood
Advertisement
For random-access containers you can use begin() + 5000 to get an iterator at that location. For containers that do not give you random-access iterators, however, you'll need to iterate from the beginning to the desired position to get such an iterator.
Ra
std::advance.

If performance turns out a problem, you're likely using wrong container.
Quote:Original post by AcidZombie24
Lets say i want to iterate from index 5000 to 5025th, how would i do this?


Why do you think you are going to want to do this?

This topic is closed to new replies.

Advertisement