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,a3736685ef876ab2 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!l22g2000hsc.googlegroups.com!not-for-mail From: Matthew Heaney Newsgroups: comp.lang.ada Subject: Re: OO Style with Ada Containers Date: Tue, 20 Nov 2007 09:17:52 -0800 (PST) Organization: http://groups.google.com Message-ID: References: <1195082906.420079.195000@d55g2000hsg.googlegroups.com> <1s27rv0gt4ujj$.3e2k326rp54d.dlg@40tude.net> <60e46dc9-d8ca-4f47-9e8a-f90a7d45e752@w28g2000hsf.googlegroups.com> <0319d921-4457-4b47-87f2-3f310aaa3d93@o6g2000hsd.googlegroups.com> <5076f153-d879-43dd-b2c8-ad61eeea241d@d61g2000hsa.googlegroups.com> <4182086a-2968-4c42-b08a-1a30b05fcf63@c29g2000hsa.googlegroups.com> NNTP-Posting-Host: 66.162.65.129 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1195579072 19239 127.0.0.1 (20 Nov 2007 17:17:52 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 20 Nov 2007 17:17:52 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: l22g2000hsc.googlegroups.com; posting-host=66.162.65.129; posting-account=umyUbgkAAADe5rQC4VzV-ffCoH4N30u3 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9,gzip(gfe),gzip(gfe) Content-Disposition: inline Xref: g2news1.google.com comp.lang.ada:18534 Date: 2007-11-20T09:17:52-08:00 List-Id: On Nov 20, 12:00 pm, Matthew Heaney wrote: > > > Sorting only the first N elements? > > (let's assume there are at least N) > > > sort(v.begin(), v.begin() + N); > > > And so on. > > procedure Op (V : in out Integer_Vectors.Vector) is > I : Extended_Index := V.First + N; > C : Cursor := To_Cursor (V, I); > begin > Sort (V.First, C); > end Op; That should really be (assuming N has type Count_Type): procedure Op (V : in out Integer_Vectors.Vector) is I : Extended_Index := V.First_Index + Count_Type'Pos (N); C : Cursor := To_Cursor (V, I); begin Sort (V.First, C); end Op; Alternatively, you could say: procedure Op (V : in out Integer_Vectors.Vector) is I : Extended_Index := V.First_Index + Count_Type'Pos (N); function Has_Element (C : Cursor) return Boolean is begin return To_Index (C) < I; end; procedure Sort is new Generic_Sort (..., Has_Element); begin Sort (V.First); end Op;