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,f2690a5e963b61b6 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!g44g2000cwa.googlegroups.com!not-for-mail From: "Matthew Heaney" Newsgroups: comp.lang.ada Subject: Re: GCC 4.0 Ada.Containers Cursor danger. Date: 5 Jul 2005 08:01:47 -0700 Organization: http://groups.google.com Message-ID: <1120575707.409086.207270@g44g2000cwa.googlegroups.com> References: <1120474891.635131.216700@g44g2000cwa.googlegroups.com> <42C98672.3020705@arcor.de> <1120537655.300974.310780@g47g2000cwa.googlegroups.com> NNTP-Posting-Host: 66.162.65.162 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1120575713 10533 127.0.0.1 (5 Jul 2005 15:01:53 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 5 Jul 2005 15:01:53 +0000 (UTC) In-Reply-To: <1120537655.300974.310780@g47g2000cwa.googlegroups.com> User-Agent: G2/0.2 Complaints-To: groups-abuse@google.com Injection-Info: g44g2000cwa.googlegroups.com; posting-host=66.162.65.162; posting-account=Zl1UPAwAAADEsUSm1PMMiDjihtBlZUi_ Xref: g2news1.google.com comp.lang.ada:11866 Date: 2005-07-05T08:01:47-07:00 List-Id: Dmitriy Anisimkov wrote: > ---------------------------- > Table.Insert (Container, "two", 2222, Cursor, Success); > > if not Success then > Some_Package.Delete_From_Container (Key => "two"); > end if; > > Table.Replace_Element (Cursor, -22222); > -------------------- This is confused. No matter what value is returned for Success (BTW: the formal parameter is named "Inserted"), the key "two" is in the map. So the predicate that follows the Insert is not necessary. As has already been pointed out, the call to Replace_Element is erroneous, since the element designated by Cursor was deleted (at least that's what I think the example is doing). The solution to the problem is to simply not use cursors: Container.Include ("two", 2222); ... Container.Include ("two", -22222); Now all is well. Just use Include, and you won't have any problems. Alternatively, you can say: Container.Include ("two", 2222); ... declare C : Cursor; B : Boolean; begin Container.Insert ("two", -22222, C, B); if not B then Replace_Element (C, By => -22222); end if; end; You really need to sit down and read the AI: -Matt