
30 Aug
2010
30 Aug
'10
4:02 p.m.
On 30.08.2010 19:26, Nevin Liber wrote:
On 29 August 2010 04:50, Mathias Gaunard<mathias.gaunard@ens-lyon.org> wrote:
for(int i=0; i<object.size(); i++)
I never understood why some people even write code like this. There are several problems with this: - using int, even though int has no direct relation with the size type of 'object'
Until C++0x and auto, it can be fairly painful to get size_type of the container, since you can't get it from the "object" variable itself. Personally, I go through the pain, but I can certainly understand why others may not. Library code, such as Boost, should do this for correctness.
In such cases I simply use std::size_t. In 99.999% of cases it is the size_type of the container and it's short enough.