comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <rm-host.bauhaus@maps.futureapps.de>
Subject: Re: Problem with generic package
Date: Wed, 16 Apr 2014 08:03:15 +0200
Date: 2014-04-16T08:03:15+02:00	[thread overview]
Message-ID: <534e1d23$0$6710$9b4e6d93@newsspool3.arcor-online.net> (raw)
In-Reply-To: <9c505412-8f30-4e1a-9374-a0d8d12f8db0@googlegroups.com>

On 15/04/14 23:58, Laurent wrote:
>
>> You can only instantiate Array_Generics.  Search_Generic is not a generic.

> Concerning (1) and (2): No I have some (1)'s and I try to put them into (2) to get rid of the (1)'s. Where I want (2) to be a package which contains a generic swap, sort and search function/procedure.

Right. As Adam explains, you need to declare them so.

generic
    the package's parameters
package p is ...

     generic -- ?
       further, the procedure's parameters -- ?
     procedure a (...) is
     
end p;

If procedure `a' should operate in terms of the package's parameters,
and no further, special, generic formal parameters of its own,
then it need not be generic on its own, since each instance of the
package also makes one procedure `a' that sees the actuals "around"
it, i.e., the types etc. passed to the package's formal parameters
on instantiation of package p.

If, on the other hand, procedure `a' needs generic parameters in
addition to those of the package in which it is declared, then it
needs to be declared as a generic as shown, preceded by its own
"generic" part.

Example:

generic
    type T is private;
package Stack is

     procedure push (Item : T);

     generic
        with function Compare (X, Y : T) return Boolean;
     procedure Sort;

end Stack;



  parent reply	other threads:[~2014-04-16  6:03 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-15 18:26 Problem with generic package Laurent
2014-04-15 19:36 ` Adam Beneschan
2014-04-15 19:44 ` Adam Beneschan
2014-04-15 20:12   ` Laurent
2014-04-15 20:37     ` Adam Beneschan
2014-04-15 20:43     ` Eryndlia Mavourneen
2014-04-15 20:47       ` Eryndlia Mavourneen
2014-04-15 21:28     ` Georg Bauhaus
2014-04-15 20:41 ` Simon Wright
2014-04-15 21:12   ` Laurent
2014-04-15 21:27     ` Adam Beneschan
2014-04-15 21:58       ` Laurent
2014-04-15 22:03         ` Adam Beneschan
2014-04-16  6:03         ` Georg Bauhaus [this message]
2014-04-16 20:37           ` Laurent
2014-04-16 21:13             ` Mike H
2014-04-16 22:31               ` Randy Brukardt
2014-04-16 23:06               ` Jeffrey Carter
2014-04-15 22:14     ` Simon Wright
2014-04-16 18:49       ` Laurent
replies disabled

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