From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,79d6bba6ba97b840 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Renaming of procedures in a generic instantiation Date: Sun, 26 Sep 2010 12:11:14 +0300 Organization: Tidorum Ltd Message-ID: <8g8h1iF1fbU1@mid.individual.net> References: <828w2orizl.fsf@stephe-leake.org> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net 3HgrnmEnAKscpxmU5++wnQm8c0IzK0WvHXM5l6Ch9YzsofXuvp Cancel-Lock: sha1:PB//up/xyT/Ty5J/hmc6bL2g/QU= User-Agent: Mozilla-Thunderbird 2.0.0.24 (X11/20100328) In-Reply-To: <828w2orizl.fsf@stephe-leake.org> Xref: g2news1.google.com comp.lang.ada:14270 Date: 2010-09-26T12:11:14+03:00 List-Id: Stephen Leake wrote: > Gene writes: > >> I'm confused about an aspect of renaming. It boils out to this little >> example: >> >> with Ada.Containers.Ordered_Sets; >> >> package Foo is >> >> type Queue is private; >> >> procedure Add(Q : in out Queue; Item : in Integer); >> >> function Is_Empty(Q : Queue) return Boolean; >> >> private >> >> package Queues is >> new Ada.Containers.Ordered_Sets(Integer, "<", "="); >> type Queue is new Queues.Set with null record; > > All primitive operations of Queues.Set are implicitly declared here, > with Queue replacing Queues.Set; that includes Set and Is_Empty. That's > what derived types are for. > >> end Foo; >> >> package body Foo is >> >> procedure Add(Q : in out Queue; Item : in Integer) >> renames Insert; > > This 'Insert' resolves to Foo.Insert (Container : in out Foo.Queue; ...); > >> function Is_Empty(Q : Queue) return Boolean >> renames Queues.Is_Empty; > > Queues.Is_Empty expects a Constainer of type Foo.Queues.Set, not Foo.Queue. > > If you replace > > type Queue is new Queues.Set with null record; > > with > > subtype Queue is Queues.Set; > > Then the Add renames will fail (because the primitive operations are not > derived), and the Is_Empty will succeed. But the subtype declaration of Queue cannot complete the initial declaration of Queue as private, so the subtype declaration must be the first and only (and public) declaration of type Queue. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .