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,51bff7cd4c35a15d X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.193.129 with SMTP id ho1mr582079pbc.8.1339028399391; Wed, 06 Jun 2012 17:19:59 -0700 (PDT) MIME-Version: 1.0 Path: l9ni16731pbj.0!nntp.google.com!news1.google.com!volia.net!news2.volia.net!feed-A.news.volia.net!news.ecp.fr!news.jacob-sparre.dk!munin.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Ada2012 : In praise of 'for ... of ... loop'... Date: Wed, 6 Jun 2012 19:19:53 -0500 Organization: Jacob Sparre Andersen Research & Innovation Message-ID: References: <74e4e6b5-20bd-4388-b4a0-dfbecc8070be@googlegroups.com> <4fc4e51d$0$6566$9b4e6d93@newsspool4.arcor-online.net> <371a4b67-1969-4cd5-90f4-d58a9b276f29@googlegroups.com> <4fc69e72$0$6633$9b4e6d93@newsspool2.arcor-online.net> NNTP-Posting-Host: static-69-95-181-76.mad.choiceone.net X-Trace: munin.nbi.dk 1339028398 9555 69.95.181.76 (7 Jun 2012 00:19:58 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Thu, 7 Jun 2012 00:19:58 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 X-RFC2646: Format=Flowed; Response Date: 2012-06-06T19:19:53-05:00 List-Id: "Georg Bauhaus" wrote in message news:4fc69e72$0$6633$9b4e6d93@newsspool2.arcor-online.net... ... > In Ada 2012, there is an Iterate function in the 2012 Vectors that > takes a parameter Start : Cursor, but not a corresponding Finish : Cursor. You don't really need one, because you can use "exit" in the for loop in order to stop the iteration early. And doing that explicitly does not suffer from the confusion that could occur if Finish is not actually after Start (in such a case, you'll probably iterate all the way to the end of the container; checking that Finish is somewhere after Start in the container is expensive in general so it isn't something that we wanted to do. So we left this operation out on purpose. This does require using the cursor version of the iterator, so it is bit more wordy: for Cur in My_Vector.Iterate(Start) loop -- Operation code here, probably using My_Vector.Reference(Cur) -- to access and modify the element in place. exit when Cur = Finish; end loop; The advantage here is that it is obvious what happens if Finish doesn't designate an element after Start in My_Vector: the iteration just goes to the end of My_Vector and stops. > So I made a Forward_Iterator that would know Start and Finish. > It has a construction function and overriding First and Next. > This made the whole program quite a bit longer. > Not necessarily worse, I think, but longer. > Perhaps more "rigorous", or "typish"? Certainly possible, but not the recommended way to write such an iteration. Do you check for the error case of Finish not following Start in the container? Randy.