comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Ada.Containers.Vectors Update_Element issue
Date: Tue, 13 May 2008 10:55:21 -0700 (PDT)
Date: 2008-05-13T10:55:21-07:00	[thread overview]
Message-ID: <4bb8bb12-225b-4790-bd12-40ef0b0adeaf@s33g2000pri.googlegroups.com> (raw)
In-Reply-To: g0cj0n$i6o$1@registered.motzarella.org

On May 13, 10:26 am, Sébastien <seb.mor...@gmail.com> wrote:
> Hi,
>
> I'm trying to use the Ada.Containers.Vectors librairies, but I don't
> know how to update element using a context.
>
> I have a list of element and I want to use Update_Element with a
> procecedure Update_Element_Process, however I want to add static
> argument to the Update_Element_Process.
>
> This could be something like :
>
> procedure My_Update(c: in out context; Element: in out Element_Type);
>
> and then
>
> procedure Update_All(c: in out context) is
> begin
>         my_list.Update_Element(1, My_Update'Access);
> end;
>
> Because My_Update is not exacly the type Update_Element_Process it's nor
> working.

procedure Update_All (c : in out context) is
    procedure Do_The_Update (Element : in out Element_Type) is
    begin
        My_Update (c, Element);
    end Do_Update;
begin
    my_list.Update_Element (1, Do_The_Update'Access);
end Update_All;

I haven't tried this.  However, it should work because the Process
parameter to Update_Element is declared as an anonymous access-
procedure type, rather than as a named access-procedure type, and this
means you can pass a nested procedure access to it without any
accessibility-level issues.  (This sort of usage is exactly why
anonymous access-subprograms types were added to Ada 2005.)


> type Update_Element_Process is
>     access procedure (Element : in out Element_Type);
>
> Note that generic doesn't help : they give me a bug error compilation
> because of Address invalid of the generic instance.
>
> I tried this:
> generic
>    c: Context;
> procedure My_Update_Generic(Element: in out Element_Type);
>
> procedure Update_All(c: in out context) is
>    procedure My_Update is new My_Update_Generic(c => c);
> begin
>         my_list.Update_Element(1, My_Update'Access);
> end;
>
> That's not working and I can understand it ;-) No dynamical address
> since the generic will instancied at runtime or something like that ...

Offhand, I *don't* understand why this wouldn't work.  It seems like
it should.  Is the compiler giving you an error message, or are you
getting exceptions or bad behavior at runtime?

But you shouldn't need a generic; the nested procedure solution should
work fine.

                              -- Adam





  reply	other threads:[~2008-05-13 17:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-13 17:26 Ada.Containers.Vectors Update_Element issue Sébastien
2008-05-13 17:55 ` Adam Beneschan [this message]
2008-05-14 15:01   ` Sébastien
2008-05-14 15:17     ` Adam Beneschan
2008-05-14 18:21       ` Sébastien
2008-05-14 21:25       ` Matthew Heaney
2008-05-14 21:33         ` Adam Beneschan
2008-05-17  8:13     ` Ludovic Brenta
replies disabled

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