comp.lang.ada
 help / color / mirror / Atom feed
From: Gene <gene.ressler@gmail.com>
Subject: Re: Renaming of procedures in a generic instantiation
Date: Tue, 28 Sep 2010 18:25:08 -0700 (PDT)
Date: 2010-09-28T18:25:08-07:00	[thread overview]
Message-ID: <54509907-9f1e-446e-b939-7e961fff717e@z30g2000prg.googlegroups.com> (raw)
In-Reply-To: 82d3rygkv9.fsf@stephe-leake.org

On Sep 28, 7:36 am, Stephen Leake <stephen_le...@stephe-leake.org>
wrote:
> Gene <gene.ress...@gmail.com> writes:
> > Thanks.  This is one variation I tried.  There is first a compiler
> > complaint that this private subtype declaration doesn't match the
> > earlier public "type Queue is private".  I take it there is no way at
> > all to declare a type private and then specify it in the private
> > section as a subtype?
>
> Ah; I had not realized the original problem you were having; how to
> implement the body for Is_Empty. The simplest approach is this:
>
> 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;
> end Foo;
> package body Foo is
>    procedure Add(Q : in out Queue; Item : in Integer)
>       renames Insert;
>
>    function Is_Empty(Q : Queue) return Boolean
>    is begin
>       return Queues.Is_Empty (Queues.Set (Q));
>    end Is_Empty;
> end Foo;
>
> --
> -- Stephe

Right.  Thanks. Understood that from the outset. Was just scratching
my head because Insert could be defined by renaming, but there was no
way to do the same for Is_Empty owing to the name clash.  I thought
there had to be some dot-path that would work.  In fact the only
recourses (using renaming) seem to be either to choose another name
for the public Is_Empty or to use the ingenous but truly crufty double
renaming trick shown by Adam Beneschan.

FWIW, I'm working out a framework for a student project, so the desire
for symmetry in the code is more pedantic than esthetic or anything
else.

Thanks guys.




  reply	other threads:[~2010-09-29  1:25 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
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 [this message]
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