comp.lang.ada
 help / color / mirror / Atom feed
From: "David C. Hoos" <david.c.hoos.sr@ada95.com>
Subject: Re: passing an array to a generic function
Date: Fri, 21 Nov 2003 05:20:52 -0600
Date: 2003-11-21T05:20:52-06:00	[thread overview]
Message-ID: <Svmvb.10164$DX3.10098@bignews5.bellsouth.net> (raw)
In-Reply-To: fc116fae.0311210231.d4a9515@posting.google.com

You need to understand and act on the messages the
compiler sends you.

Accordingly, the following code will compile:

generic
   type Index is (<>);
   type Item is private;
   type Arr is array(Index) of Item;
   with function "="(I1,I2 : Item) return Boolean is <>;

   function Filter_Array(A: Arr) return Arr;

   type Index is new Integer range 1 .. 23;
   type Item is new Character;
   type Arr is Array(Index) of Item;

   function Filter_String is new Filter_Array(Index,Item,Arr,"=");

However. when you declare types as new "some other type",
you're creating new types that are distinct from
the "some other type."  Therefore, if as the name of
your instantiation implies, you intend to pass objects
of type string to it, you would do better to do this:

generic
   type Index is (<>);
   type Item is private;
   type Arr is array(Index) of Item;
   with function "="(I1,I2 : Item) return Boolean is <>;

   function Filter_Array(A: Arr) return Arr;

   subtype Index is Integer range 1 .. 23;
   subtype Arr is String (Index);

   function Filter_String is new Filter_Array(Index, Character, Arr, "=");

"Mr. J." <ratsonjaniv@hotmail.com> wrote in message
news:fc116fae.0311210231.d4a9515@posting.google.com...
> hi,
>
> this is my generic function:
>
> generic
>    type Index is (<>);
>    type Item is private;
>    type Arr is array(Index range <>) of Item;
>    with function "="(I1,I2 : Item) return Boolean is <>;
>
>    function Filter_Array(A: Arr) return Arr;
>
> Now, I wanna write a create a Filter_String function according to it:
>
>    type Index is new Integer;
>    type Item is new Character;
>    type Arr is Array(1..23) of character;
>
>    function Filter_String is new Filter_Array(Index,Item,Arr,"=");
>
> As U all experts guessed it won't compile, my question is how to pass
> the array of character to my new function ?
>
> 10x,
> J.
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada-france.org
> http://www.ada-france.org/mailman/listinfo/comp.lang.ada
>
>




  parent reply	other threads:[~2003-11-21 11:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-21 10:31 passing an array to a generic function Mr. J.
2003-11-21 11:03 ` Lutz Donnerhacke
2003-11-21 11:20 ` David C. Hoos [this message]
2003-11-21 11:35 ` Jean-Pierre Rosen
replies disabled

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