comp.lang.ada
 help / color / mirror / Atom feed
From: Ryan <rtarpine@hotmail.com>
Subject: Array-like object indexing
Date: Sat, 17 Aug 2002 17:22:33 -0700
Date: 2002-08-17T17:22:33-07:00	[thread overview]
Message-ID: <3D5EE8C9.2080601@hotmail.com> (raw)

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.

Should the responsibility for this rest on the package or the user? 
Would it be a better to return 1 and 0, or to force a user of the 
package to instantiate it with an indexing type that starts at -1 
instead even though -1 should never be used to actually look into the 
array?  What are your opinions on this?

Thank you,
Ryan Tarpine




             reply	other threads:[~2002-08-18  0:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-18  0:22 Ryan [this message]
2002-08-19  3:55 ` Array-like object indexing R. Tim Coslet
2002-08-19  5:36 ` Simon Wright
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