This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Optimzed vs. readable code
> Le Tue, 29 Nov 2005 10:45:19 -0800, Howard Hinnant a écrit�:
>> You are the victim of unfortunate timing. :-) I just posted in
>> another thread:
>>> That philosophy is basically: Keep things as simple as possible.
>>> Don't gratuitously add code just to see if the compiler can optimize
>>> it back out.
>
> I agree with that. The thing is, in CS courses on compilation, one can
> learn that it is nowadays a so classic optimization that one can safely
> expect it from any decent compiler.
Really? It is trivial in the case of a pointer, or say a vector::iterator,
which is just a thin wrapper over a pointer. I expect it gets much harder
for types with more complex iterators. In particular, the debugging
library has iterators which register themselves with the container they
are used in, for tracking purposes. The registration and unregistration is
reduced somewhat by the compiler, but not totally removed (mainly because
it has a visible side-effect, it might resize the container which contains
the iterators of the container).
Chris