Does std::vector::size() recompute the size of the vector each time it’s called, or does it maintain a counter that is only modified when the vector is modified? For example, if I have class with a std::vector<double> member, would there be any speed benefit to keeping track of its size in a separate counter?
Does std::vector::size() recompute the size of the vector each time it’s called, or does
Share
size()is guaranteed to have constant time complexity, and in any sane implementation will be as fast an operation as you can possibly have.