comp.lang.ada
 help / color / mirror / Atom feed
From: mheaney@on2.com (Matthew Heaney)
Subject: Re: Charles: missing vector iterators
Date: 14 Nov 2002 08:04:54 -0800
Date: 2002-11-14T16:04:54+00:00	[thread overview]
Message-ID: <1ec946d1.0211140804.42621077@posting.google.com> (raw)
In-Reply-To: 3dd29387$0$303$bed64819@news.gradwell.net

porton@ex-code.com (Victor Porton) wrote in message news:<3dd29387$0$303$bed64819@news.gradwell.net>...
> Why in Charles.Vectors iterators are missing even despite it is 
> modelled after STL?

Because iterators for vectors are too fragile.

An unbounded vector automatically grows as necessary during
insertions.  This works by deallocating the existing internal array,
reallocating a new (longer) array, and copying the existing elements
onto the new array.

The issue is that an iterator designates the old array, which gets
deallocated.  It's too easy for forget this fact, which means dangling
references occur.

The whole problem goes away by simply using the index subtype to refer
to elements in the vector, instead of an iterator.

Realize that the iterator exists in the STL because of the nature of
template expansion in C++.  In Ada, a separate iterator is not
necessary because the generic actual subprogram only needs to match
the signature of the generic formal, not its name (which is not the
case in C++).

Remember that Charles is *modelled* on the STL, but it is not a
literal port of the STL.  Charles is first and foremost an Ada
library, and it takes advantage of specific features of the Ada
language, specifically nested subprograms.


> Iterators are good for many things, including reliability:

Just the opposite.  A vector iterator is very UNreliable.
 
>Probability to mess iterators is 
> lesser than to mess natural number indexes because iterators are more 
> type-safe.

Wrong for vectors.  I don't know what would ever motivate you to think
this, when iteration over a scalar range is so high level in Ada:

for I in I_Subtype loop
   for J in J_Subtype loop
     ...

This is hard to get wrong.

 
> Please add these.

Your suggestion is noted, and rejected.

 
> BTW, may be put Chrles on SourceForge or something that if e.g. I will 
> want to submit a patch it would become simpler?

You can get more immediate feedback by sending me email directly.  CLA
is probably not the most suitable forum for discussing Charles
features.

mheaney at on2 dot com



  parent reply	other threads:[~2002-11-14 16:04 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-13 17:15 Charles: missing vector iterators Victor Porton
2002-11-14  9:22 ` Preben Randhol
2002-11-14 12:10 ` Marc A. Criley
2002-11-14 15:30   ` Preben Randhol
2002-11-14 16:04 ` Matthew Heaney [this message]
2002-11-15  7:10 ` Victor Porton
2002-11-15  9:36   ` Preben Randhol
2002-11-15  9:37   ` Preben Randhol
2002-11-15  7:27 ` Victor Porton
2002-11-16  0:10   ` Matthew Heaney
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox