How do I get the index of an iterator of an std::vector?
I would prefer it – vec.begin() precisely for the opposite reason given by Naveen: so it wouldn’t compile if you change the vector into a list. If you do this during every iteration, you could easily end up turning an O(n) algorithm into an O(n^2) algorithm. Another option, if you don’t jump around in the … Read more