From: Stephen Leake <stephen_leake@stephe-leake.org>
Subject: Re: Renaming of procedures in a generic instantiation
Date: Sun, 26 Sep 2010 04:45:18 -0400
Date: 2010-09-26T04:45:18-04:00 [thread overview]
Message-ID: <828w2orizl.fsf@stephe-leake.org> (raw)
In-Reply-To: f0affc67-0080-410f-9595-b91f893ec6f5@a19g2000yql.googlegroups.com
Gene <gene.ressler@gmail.com> 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.
--
-- Stephe
next prev parent reply other threads:[~2010-09-26 8:45 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-26 0:43 Renaming of procedures in a generic instantiation Gene
2010-09-26 6:54 ` Niklas Holsti
2010-09-26 7:40 ` Jeffrey Carter
2010-09-26 8:41 ` Niklas Holsti
2010-09-26 17:07 ` Jeffrey Carter
2010-09-26 14:52 ` Gene
2010-09-26 15:04 ` Dmitry A. Kazakov
2010-09-26 8:45 ` Stephen Leake [this message]
2010-09-26 9:11 ` Niklas Holsti
2010-09-27 1:18 ` Gene
2010-09-28 11:36 ` Stephen Leake
2010-09-29 1:25 ` Gene
2010-09-27 19:23 ` Adam Beneschan
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox