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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3f8d8581bfd0fa44 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-08-18 22:53:02 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!kibo.news.demon.net!news.demon.co.uk!demon!pogner.demon.co.uk!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Array-like object indexing Date: 19 Aug 2002 06:36:25 +0100 Organization: Pushface Sender: simon@smaug Message-ID: References: <3D5EE8C9.2080601@hotmail.com> NNTP-Posting-Host: pogner.demon.co.uk X-NNTP-Posting-Host: pogner.demon.co.uk:62.49.19.209 X-Trace: news.demon.co.uk 1029736379 nnrp-12:7874 NO-IDENT pogner.demon.co.uk:62.49.19.209 X-Complaints-To: abuse@demon.net User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Xref: archiver1.google.com comp.lang.ada:28207 Date: 2002-08-19T06:36:25+01:00 List-Id: Ryan writes: > I've recently been playing with making all the standard data > structures in Ada to prepare myself for writing my first major > project. Currently I'm writing a resizable-array package. I am > trying to make it as similar to built-in arrays as possible, with > functions for First, Length and other useful operations and > attributes. It is a generic package instantiated with a type for > the elements to be stored and a type for indexing. I've run into a > small problem with respect to the indexing type. > > I'm not sure how to represent the boundaries of an empty array > without raising a constraint error in some cases. If an array is > being indexed by Natural, for example, and the first index should be > 0 (as makes sense in many situations), then what should the First > and Last functions (intended to work like their analogous > attributes) return? I cannot return 0 and -1 because -1 would raise > a constraint error. The non-Ada C++ STL approach is to denote the end of the range by a value notionally one past the last valid element. It's not obvious that Last is the right name for an operation returning such a value, cf My_Array'Last.