Matt Austern
Wed Jul 30 23:44:00 GMT 2003

On Wednesday, July 30, 2003, at 07:59  AM, Thomas Kunert wrote:

> Currently, vector<T>::iterator is defined as some class type. I'd like 
> to give some arguments for using T* instead.
> The main advantage I see is speed of the produced code. Sure, for an 
> flawlessly optimizing compiler, the resulting code should be 
> identical. But real world compilers, including GCC, have flaws and 
> hence may produce
> worse code when using a class type. Especially for unoptimized 
> compilations,
> the resulting code is very different. And, of course, the speed even of
> unoptimized code is important.
> The next advantage is simpler code in the library itself, which 
> simplifies
> bug hunting in the library as well as in user code.
> The only disadvantage I see it that T* allows the user to write 
> non-portable
> code. This is not really a problem, because such code will be found 
> immediately
> and fixed easily if necessary.
> Am I missing something?

Only the history.  Vector<T>::iterator used to be T*.  The libstdc++ 
maintainers deliberately changed it to be a class that wraps T*, with 
full awareness of both the advantages and disadvantages you mention.  I 
don't think there's any chance of convincing them to change it back.


More information about the Libstdc++ mailing list