Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-06-15 07:40:19

Bo Peng wrote:
> Bo Peng wrote:
> I read /usr/include/c++/3.2.2/bits/stl_vector.h, here is the answer to
> my own questions:
>> 1. How is size() implemented in vector<>?
> end - start pointer. Not a reference to a variable. Too bad.

You aren't exactly required to call size() every iteration, you know.

    for( int i = 0, n = v.size(); i < n; ++i )

will work fine (or 'size_t i ...' if you like unsigned). Otherwise the
optimizer would need to prove that v.size() is invariant. The idiomatic
approach is to use iterators, of course, but compilers didn't seem to
vectorize iterator-based loops last time I tried.

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at