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,fe5e779eaf4ecf02 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!feeder.erje.net!newsfeed01.sul.t-online.de!t-online.de!news.belwue.de!news.uni-stuttgart.de!not-for-mail From: Stefan Bellon Newsgroups: comp.lang.ada Subject: Re: Returning ranges from a function (was: How to loop (elegant) throug a vector ?) Date: Sun, 22 Jun 2008 20:47:13 +0200 Organization: Comp.Center (RUS), U of Stuttgart, FRG Message-ID: <20080622204713.2127db4f@cube.tz.axivion.com> References: <20080620191237.5971480b@cube.tz.axivion.com> <6ebe0cd8-288e-4997-94d7-61905fd2dfc0@r66g2000hsg.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Trace: infosun2.rus.uni-stuttgart.de 1214160416 7577 129.69.226.21 (22 Jun 2008 18:46:56 GMT) X-Complaints-To: news@news.uni-stuttgart.de NNTP-Posting-Date: Sun, 22 Jun 2008 18:46:56 +0000 (UTC) X-Newsreader: Claws Mail 3.4.0 (GTK+ 2.12.10; i486-pc-linux-gnu) X-URL: http://www.axivion.com/ Xref: g2news1.google.com comp.lang.ada:805 Date: 2008-06-22T20:47:13+02:00 List-Id: On Sun, 22 Jun, Maciej Sobczak wrote: > On 20 Cze, 19:12, Stefan Bellon wrote: > > for I in Get_Range'Range loop > > Do_Something (I); > > end loop; > > > > It's not as elegant as I wished (because of the additional 'Range), > > but it is simple and light-weight enough to be usable. > > As far as I can tell, it creates the physical array that might not be > necessarily optimized out by the compiler. You need to store it > somewhere. You need to store the two words for First and Last (or First and Length). And indeed, this is what GNAT does. The 'Size of the array object returned is two words in size. > It would be nicer to return a "range" that is not dependent on memory > constraints. See xrange in Python. I think you cannot get smaller than the two words. The question is whether this optimisation (for 'Size use 0) can always be guaranteed. -- Stefan Bellon