Does the c++ compiler take care of cases like, buildings is vector:
for (int i = 0; i < buildings.size(); i++) {}
that is, does it notice if
buildings.size()
will likely be inlined by the compiler to directly access the private size field on the vector
class. So you shouldn't separate the call to size
. This kind of micro-optimization is something you don't want to worry about anyway (unless you're in some really tight loop identified as a bottleneck by profiling).