In the following code:
std::vector var;
for (int i = 0; i < var.size(); i++);
Is the
The size()
member function is called each time, but it would be a really bad implementation that wouldn't inline it, and a strange one where it wouldn't be a simple access of a fixed datum or a subtraction of two pointers.
Anyway, you shouldn't worry yourself with such trivialities until you have profiled your application and found out that this is a bottleneck.
However, what you should pay attention to is:
std::vector::size_type
. i++
might be slower than ++i
.Therefore, the loop should be:
for(vector::size_type i=0; i