From: Simon Wright <simon@pushface.org>
Subject: Re: Array-like object indexing
Date: 19 Aug 2002 06:36:25 +0100
Date: 2002-08-19T06:36:25+01:00 [thread overview]
Message-ID: <x7vvg67e7fq.fsf@pushface.org> (raw)
In-Reply-To: 3D5EE8C9.2080601@hotmail.com
Ryan <rtarpine@hotmail.com> 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.
next prev parent reply other threads:[~2002-08-19 5:36 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-08-18 0:22 Array-like object indexing Ryan
2002-08-19 3:55 ` R. Tim Coslet
2002-08-19 5:36 ` Simon Wright [this message]
2002-08-19 19:33 ` Ryan
2002-08-19 19:49 ` Darren New
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox