Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ STL

Name: Anonymous 2009-08-28 12:46

Is it faster to iterate through stl vector with the [] operator or an iterator?
I would think that the iterator is faster but I'm too lazy to test.

Name: Anonymous 2009-08-28 20:21

Any properly optimized STL implementation will have iterators directly map to pointers and the [] operator also be a pointer operation:

template <class _T>
class vector {
 ...
 typedef _T *iterator;
 ...
 iterator begin() { return vec; }
 iterator end() { return vec+used; }
 _T operator[](size_t offs) { return *(vec+offs); }
 ...
 size_t capacity, used;
 _T *vec;
};

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List