comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Array index overloading
Date: Thu, 7 Aug 2014 00:17:12 -0500
Date: 2014-08-07T00:17:12-05:00	[thread overview]
Message-ID: <lrv24o$jbf$1@loke.gir.dk> (raw)
In-Reply-To: ppKdnfmkdIYX-n_ORVn_vwA@giganews.com

"Peter Chapin" <PChapin@vtc.vsc.edu> wrote in message 
news:ppKdnfmkdIYX-n_ORVn_vwA@giganews.com...
> On 2014-08-06 12:47, marmaduke.woodman@univ-amu.fr wrote:
>
>> Handling index arrays and generating an output array is something I can 
>> write, so my question is if the syntax can be overloaded, or I should 
>> expect to implement an explicit "slice" function?
>
> As Pascal mentioned one dimensional array slices are supported in Ada by
> just indexing using notation A(I .. J) for array A. If you want
> non-unity strides, or multi-dimensional slices, or some other fancier
> effects, you will need to turn to a library of some kind.
>
> Although as I write this I'm wondering if a subtype with a static
> predicate could cover some of those bases. Hmm.

You'll find that it is illegal to declare an array with an index subtype 
that has one or more predicates. We didn't want compilers to have to support 
"holey" arrays or slices.

One could create a container that supported almost any sort of indexing that 
someone wanted. In particular, the Map containers support using the indexed 
notation on the Key_Type, and the Key_Type can be pretty much anything you 
want, so long as it is non-limited.

So, with appropriate declarations, you can write:

     Storage ("Bob") := Obj1;
     Storage ("Randy") := Obj2;
     if Storage ("Tuck") = Storage ("Randy") then ...

and so on.

                              Randy.



      reply	other threads:[~2014-08-07  5:17 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-06 16:47 Array index overloading marmaduke.woodman
2014-08-06 16:53 ` Pascal Obry
2014-08-06 17:38   ` marmaduke.woodman
2014-08-06 19:25     ` Georg Bauhaus
2014-08-06 19:43     ` Adam Beneschan
2014-08-06 21:51     ` Pascal Obry
2014-08-06 23:53     ` Shark8
2014-08-06 17:36 ` Peter Chapin
2014-08-07  5:17   ` Randy Brukardt [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox