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!news4.google.com!news.glorb.com!npeer.de.kpn-eurorings.net!newsfeed.arcor.de!news.arcor.de!not-for-mail Date: Wed, 13 Jul 2005 03:15:57 +0200 From: Georg Bauhaus User-Agent: Debian Thunderbird 1.0.2 (X11/20050331) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: GCC 4.0 Ada.Containers Cursor danger. References: <1120474891.635131.216700@g44g2000cwa.googlegroups.com> <1120575076.876798.108220@g44g2000cwa.googlegroups.com> <1120583470.429264.325450@g43g2000cwa.googlegroups.com> <42cb8d21$0$22761$9b4e6d93@newsread2.arcor-online.net> <42cd064c$0$10817$9b4e6d93@newsread4.arcor-online.net> <42cda8c4$0$22780$9b4e6d93@newsread2.arcor-online.net> <1u3hh2597i4ne$.1ryetugksbmus.dlg@40tude.net> <1120834341.499757.133770@g43g2000cwa.googlegroups.com> <1121093867.964444.232420@g14g2000cwa.googlegroups.com> <42d2bc2d$0$20148$9b4e6d93@newsread2.arcor-online.net> <1121134291.379399.79460@z14g2000cwz.googlegroups.com> In-Reply-To: <1121134291.379399.79460@z14g2000cwz.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <42d46b51$0$18005$9b4e6d93@newsread4.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 13 Jul 2005 03:16:01 MEST NNTP-Posting-Host: aa8e1e6d.newsread4.arcor-online.net X-Trace: DXC=Ui:F9iDl[RDUhhl_USDNiO:ejgIfPPldDjW\KbG]kaMHAV6U:Z=fE=OgHAGJm4W53EhP3YJKgE\jL8VI MMM wrote: >>Cursors are among the means to choose different >>containers when the need arises, ideally without disturbing the rest of >>the program. > > I can't say I understand you here, but anyway, how cursors could > help to change container type without disturbing the rest of the > program? > [...] > Care to provide an example of such a generic algorithm? Here is a silly example demonstrating a subprogram that is independent of any specific container. That is, you can choose any instance in place of My_Container. As arguments to the following function, use cursors returned by Floor and Ceiling (to mark a range of associations in a map.) Use First and Last of a set to express forall. Do the same using a vector. with My_Container; -- some instance of some Ada.Container ("abstract" if you wish) function gen_find (first, last: My_Container.Cursor; item: My_Container.Cursor) return My_Container.Cursor -- The first cursor of the sequence from `first` to `last` that designates -- an elemenent equal to the element designated by `item`. -- `No_Element` if not found. is use My_Container; p: Cursor := first; off: constant Cursor := Next(last); begin loop exit when p = off or else Element(p) = Element(item); next(p); end loop; if p = off then return No_Element; else return p; end if; end gen_find;