Re: Unified Ada library

From: Hyman Rosen (hyrosen_at_mail.com)
Date: 04/19/04


Date: Mon, 19 Apr 2004 10:30:14 -0400

Georg Bauhaus wrote:
> Could you comment on the importance of iterators and generic
> algorithms in the template libraries?

You can write your algorithms for the most part as if you were
using pointers to iterate over arrays. Because no virtual
operations are involved, and because C++ compilers have been
taught that inlining template code is vital, the resulting
compiled code becomes very efficient. If the pointer-like code
attempts an operation that would be inefficent for some given
container (such as trying to subtract two iterators when they
refer to a linked list instead of an array), the code won't
compile because the operation isn't defined.

The idea was to have containers and algorithms that did not force
code to pay runtime abstraction penalties over use of plain arrays.
It was vital that code which used std::vector should be as efficient
as plain arrays for the things that plain arrays could do, otherwise
the community would have rejected the standard containers.

Not only that, having the algorithms look like array/pointer operations
allows them to be used on arrays as well as containers, since pointers
are iterators, and it comforts C programmers who can write code in the
style they are used to.



Relevant Pages

  • Re: Why use STL?
    ... > Or am I completely misunderstanding what "iterators" are all about? ... It's the fact that STL container classes don't implement any algorithms (in ... operate on the standard containers and on any other containers you'd care to ...
    (microsoft.public.vc.stl)
  • Re: Best Data Structures Book
    ... and standard algorithms persuaded me to port and adapt the SGI STL to ... Maybe you can use it or at least compare your implementations with it. ... I wish to bring to my libraries are iterators and an generic ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Unified Ada library
    ... expressed using Set Iterators in e.g. generic union and intersection ... Charles generic algorithms, AFAICS.) ... For example, all persons named "Miller" from a telephone directory, ...
    (comp.lang.ada)
  • Re: Using iterators and efficiency.
    ... >>list of memory blocks preallocated to the right size. ... Iterators are far more versatile than the simple visitor. ... an item from the container etc etc. ... > ten, the problem is in the algorithms, perhaps the amount of work ...
    (comp.object)