Boost logo

Geometry :

Subject: [ggl] pre-/post-increment op on iterators
From: Mateusz Loskot (mateusz)
Date: 2009-04-25 18:23:08


Barend Gehrels wrote:
>> OK, this test case does not show incredible performance gain, but
>> if we look around on the Web and Usenet comp.lang.c++.* we can find
>> different results - all if not most of them show that pre-increment
>> operator performs better. How better, numbers are different but may
>> be big :-)
>>
>> Here is one of examples:
>>
>> http://antonym.org/2008/05/stl-iterators-and-performance.html
>
>
> Great. They also mention boost::foreach. Actually I recently did
> consider using this, it makes things concise. However, it is not used
> often nternally within boost libraries. Don't know why not...

Yes, boost::foreach is a good idea but perhaps it's too big revolution
in terms of C++ programmers habits, similarly why std::for_each is
rarely used (in general) :-) for/while loops still are preferred.

>>> So yes, we should change it. Good you point it out.
>>>
>>
>> OK, I will.
>
> Also great, but I don't know if you intended to say that you'll
> change all of them? That will be a lot. Cannot be done automatically,
> alas, because of things like prev = it++ (where pre-increment will
> destroy behaviour...)

Certainly, replacing all in one shot is potentially risky and would be
time consuming, so automatic update is not possible.
I will be replacing it by-the-way while doing other refactoring work - I
spot post-increment used for iterator, then I check if it's safe to
replace with pre-increment and I apply changes or add TODO comment if
it's not obvious without running the code.

So, it's going to be applied in pieces :-)

Best regards,

-- 
Mateusz Loskot, http://mateusz.loskot.net
Charter Member of OSGeo, http://osgeo.org

Geometry list run by mateusz at loskot.net