comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Ada.Containers.Vectors - querying multiple elements
Date: 29 Apr 2005 14:34:11 -0400
Date: 2005-04-29T14:34:11-04:00	[thread overview]
Message-ID: <wccfyx94el8.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: hlhce.936$HL2.780@newsread3.news.pas.earthlink.net

Jeffrey Carter <spam@spam.com> writes:

> Randy Brukardt wrote:
> 
> > It's not really corrected in Ada 2006; it has additional aggregates that
> > help, but the basic problem of having to mess with the bounds still exists:
> >      Obj : Some_Array (Enum'First ..
> > Enum'Val(Enum'Pos(Enum'First)+Some_Length-1);
> > doesn't work if Some_Length = 0 and there is no general way to fix
> > that. You
> > just have to special case Some_Length = 0 and that is unpleasant.
> 
> Right, but you can say
> 
> Obj : Some_Array := Some_Array'(<>);
> 
> (I hope I've remembered the syntax correctly)

I don't see any such syntax in the draft RM,
and I'm not sure which syntax you're referring to.

>... and Obj'Length = 0; there
> was no way to do this before if Enum'First = Enum'Last. And you should
> be able to convert Obj into a corresponding unbounded array.

Every array object has a 'Last in Ada.  It's simply impossible to create
an array with a 'Last that does not exist.  So a zero-length array
whose 'First is the lower bound of the base range is simply impossible.
I don't think this has changed in Ada 2006.

I don't think it's a problem, either.  If you want zero-length arrays,
then you're counting things, and signed integers are the appropriate
index type.  Arrays indexed by enums are usually things like tables,
and therefore not empty.  Can you think of an example where you want
an empty array, and a enum or modular type is appropriate for the index?
I can't think of any at the moment.

> > The solution that Ada.Containers.Vector took to this problem is essentially
> > to ban instantiating it with subtypes where 'First = 'Base'First. (OK, you
> > can do the instantiation, but it will raise Constraint_Error.) One can argue
> > whether that is the best solution, but it seems clear that all of the
> > possible solutions are ugly.
> 
> Yes. I think this solution is uglier than having Last = First if Length = 0.

Last = First seems just plain wrong, to me.  You want to loop from First
up to Last -- if Length = 0, that loop had better not do anything.

- Bob



  reply	other threads:[~2005-04-29 18:34 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-26 11:43 Ada.Containers.Vectors - querying multiple elements Duncan Sands
2005-04-26 14:12 ` Georg Bauhaus
2005-04-26 14:39   ` Duncan Sands
2005-04-26 15:44     ` Matthew Heaney
2005-04-26 16:05       ` Duncan Sands
     [not found]       ` <1114531544.32583.142.camel@localhost.localdomain>
     [not found]         ` <426E72C3.9070108@on2.com>
2005-04-26 16:59           ` Duncan Sands
     [not found]           ` <1114534751.32583.144.camel@localhost.localdomain>
     [not found]             ` <426E73DE.2070505@on2.com>
2005-04-26 17:08               ` Duncan Sands
2005-04-26 18:17                 ` Martin Dowie
2005-04-26 18:48                   ` Duncan Sands
2005-04-26 18:59           ` Duncan Sands
2005-04-26 19:05             ` Georg Bauhaus
2005-04-26 20:34               ` Duncan Sands
2005-04-26 21:47               ` Dr. Adrian Wrigley
2005-04-26 23:21                 ` Marius Amado Alves
     [not found]                 ` <9decddc0038674b3c85aeceefb4d3b83@netcabo.pt>
2005-04-27  8:15                   ` Duncan Sands
     [not found]                   ` <1114589729.10418.13.camel@localhost.localdomain>
2005-04-27 11:49                     ` Marius Amado Alves
2005-04-28  0:36                       ` Randy Brukardt
2005-04-28  7:09                         ` Duncan Sands
2005-04-27 11:10                 ` Georg Bauhaus
2005-04-27 11:57                   ` Duncan Sands
2005-04-28 14:17       ` Duncan Sands
2005-04-27  4:59   ` Jeffrey Carter
2005-04-27  7:21     ` Duncan Sands
2005-04-28  2:54       ` Jeffrey Carter
2005-04-28  7:15         ` Duncan Sands
2005-04-28 12:27           ` Matthew Heaney
2005-04-28 13:18           ` Matthew Heaney
2005-04-28 13:53             ` Duncan Sands
2005-04-29  2:46           ` Jeffrey Carter
2005-04-29 18:22             ` Robert A Duff
2005-04-28  7:18         ` Duncan Sands
2005-04-28  0:33     ` Randy Brukardt
2005-04-28  3:09       ` Jeffrey Carter
2005-04-28 20:55         ` Randy Brukardt
2005-04-29  2:54           ` Jeffrey Carter
2005-04-29 18:34             ` Robert A Duff [this message]
2005-04-29 20:18               ` Randy Brukardt
2005-04-29 20:00             ` Randy Brukardt
2005-04-30  4:06               ` Jeffrey Carter
2005-04-29  7:52           ` Dmitry A. Kazakov
2005-04-29 20:26             ` Randy Brukardt
2005-04-30  9:24               ` Dmitry A. Kazakov
2005-05-02  3:21                 ` Randy Brukardt
2005-05-02 17:04                   ` Dmitry A. Kazakov
2005-05-02 18:57                     ` Robert A Duff
2005-05-03  8:14                       ` Dmitry A. Kazakov
2005-05-03 23:30                         ` Robert A Duff
2005-05-05 10:51                           ` Dmitry A. Kazakov
2005-05-07  1:20                             ` Matthew Heaney
2005-05-07  7:17                               ` Dmitry A. Kazakov
     [not found] <1114515832.32583.41.camel@localhost.localdomain>
     [not found] ` <426E5A0B.3010109@on2.com>
2005-04-26 16:00   ` Duncan Sands
2005-04-28  0:54     ` Randy Brukardt
replies disabled

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