comp.lang.ada
 help / color / mirror / Atom feed
From: "R. Tim Coslet" <R_Tim_Coslet@pacbell.net>
Subject: Re: Array-like object indexing
Date: Mon, 19 Aug 2002 03:55:30 GMT
Date: 2002-08-19T03:55:30+00:00	[thread overview]
Message-ID: <B985B7FC.4F28%R_Tim_Coslet@pacbell.net> (raw)
In-Reply-To: 3D5EE8C9.2080601@hotmail.com

Have First and Last return Index_Type'Base. At least for numeric types this
will eliminate most cases of the Constraint_Error that you don't want.
(Natural'Base does include -1 in its 'Range even though Natural doesn't)

Unfortunately you can't declare your own functions to return "universal"
types, like the attributes return.

-- 
        R. Tim Coslet
        r_tim_coslet@pacbell.net

Technology, n. Domesticated natural phenomena.


> From: Ryan <rtarpine@hotmail.com>
> Newsgroups: comp.lang.ada
> Date: Sat, 17 Aug 2002 17:22:33 -0700
> Subject: Array-like object indexing
> 
> 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-19  3:55 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 [this message]
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