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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Received: by 2002:a0c:e8ce:: with SMTP id m14mr23670838qvo.164.1572358841879; Tue, 29 Oct 2019 07:20:41 -0700 (PDT) X-Received: by 2002:a9d:1291:: with SMTP id g17mr17669226otg.76.1572358841592; Tue, 29 Oct 2019 07:20:41 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!j16no595432qtl.0!news-out.google.com!x9ni456qti.1!nntp.google.com!j16no595423qtl.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 29 Oct 2019 07:20:41 -0700 (PDT) In-Reply-To: <6ea868a2-6f4b-413c-955d-08e8735f2880@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2a02:a03f:e3e9:4d00:1260:4bff:fe89:deb2; posting-account=kTRirAoAAACnF_wtAOSamxYBSVvmJuCa NNTP-Posting-Host: 2a02:a03f:e3e9:4d00:1260:4bff:fe89:deb2 References: <6ea868a2-6f4b-413c-955d-08e8735f2880@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: How to Iterate over all elements of a hashed_map. From: Alain De Vos Injection-Date: Tue, 29 Oct 2019 14:20:41 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader01.eternal-september.org comp.lang.ada:57369 Date: 2019-10-29T07:20:41-07:00 List-Id: I found code which takes a different approach, here there is a function .Iterate public ... , with Ada.Containers.Indefinite_Hashed_Maps; with Ada.Strings.Hash; with Ada.Text_IO; use Ada.Text_IO; procedure Show_Hashed_Map is package Integer_Hashed_Maps is new Ada.Containers.Indefinite_Hashed_Maps (Key_Type => String, Element_Type => Integer, Hash => Ada.Strings.Hash, Equivalent_Keys => "="); use Integer_Hashed_Maps; M : Map; -- Same as: M : Integer_Hashed_Maps.Map; begin M.Include ("Alice", 24); M.Include ("John", 40); M.Include ("Bob", 28); if M.Contains ("Alice") then Put_Line ("Alice's age is " & Integer'Image (M ("Alice"))); end if; -- Update Alice's age -- Key must already exist in M. -- Otherwise an exception is raised. M ("Alice") := 25; New_Line; Put_Line ("Name & Age:"); for C in M.Iterate loop Put_Line (Key (C) & ": " & Integer'Image (M (C))); end loop; end Show_Hashed_Map;