comp.lang.ada
 help / color / mirror / Atom feed
From: Shark8 <OneWingedShark@gmail.com>
Subject: Re: Array index overloading
Date: Wed, 06 Aug 2014 17:53:42 -0600
Date: 2014-08-06T17:53:42-06:00	[thread overview]
Message-ID: <eezEv.138700$qR1.130247@fx02.iad> (raw)
In-Reply-To: <dad0dc0f-80ff-4436-a380-298a3a933209@googlegroups.com>

On 06-Aug-14 11:38, marmaduke.woodman@univ-amu.fr wrote:
> So V(2 .. 4) is possible, but is the equivalent V((2, 3, 4)) ?


Kinda; the following should show how you'd do your select-by-vector sort 
of thing:

     -- This is your index-type, and a 'vector' thereof.
     Subtype Index_Type is Positive;
     Type Index_Array is Array(Positive range <>) of Index_Type;

     -- This is the Array-type you're interested in.
     Type Collection_Array is Array(Index_Type range <>) of Float;

     -- This is how you can apply a 'vector' to that array to select
     -- disjoint components.
     Function Get_Items( Indices  : Index_Array;
                         From     : Collection_Array
                       ) return Collection_Array is
     Begin
         Return Result: Collection_Array(1..Indices'Length) do
             for Index in Indices'Range loop
                 Offsets:
                 declare
                     From_Index : Constant Positive := Indices(Index);
                     To_Index   : Constant Positive := 
Result'First+Index-Indices'First;
                 begin
                     Result(To_Index) := From(From_Index);
                 end Offsets;
             end loop;
         end return;
     End Get_Items;

  parent reply	other threads:[~2014-08-06 23:53 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 [this message]
2014-08-06 17:36 ` Peter Chapin
2014-08-07  5:17   ` Randy Brukardt
replies disabled

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