From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,1fa85f3df5841ae1 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.maxwell.syr.edu!newsswitch.lcs.mit.edu!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Ada.Containers.Vectors - querying multiple elements Date: 29 Apr 2005 14:34:11 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <426e4c2b$0$7515$9b4e6d93@newsread2.arcor-online.net> <0uYbe.542$BE3.229@newsread2.news.pas.earthlink.net> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1114799651 7019 192.74.137.71 (29 Apr 2005 18:34:11 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Fri, 29 Apr 2005 18:34:11 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: g2news1.google.com comp.lang.ada:10827 Date: 2005-04-29T14:34:11-04:00 List-Id: Jeffrey Carter 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