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,b553d2c02a2df59f X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news4.google.com!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!stamper.news.atl.earthlink.net!newsread1.news.atl.earthlink.net.POSTED!14bb18d8!not-for-mail Sender: Matthew Heaney@MHEANEYIBMT43 Newsgroups: comp.lang.ada Subject: Re: limited types (Was: Records that could be arrays) References: From: Matthew Heaney Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Sat, 25 Feb 2006 02:21:13 GMT NNTP-Posting-Host: 24.149.57.125 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.news.atl.earthlink.net 1140834073 24.149.57.125 (Fri, 24 Feb 2006 18:21:13 PST) NNTP-Posting-Date: Fri, 24 Feb 2006 18:21:13 PST Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: g2news1.google.com comp.lang.ada:3155 Date: 2006-02-25T02:21:13+00:00 List-Id: "Randy Brukardt" writes: > Of course, you often do need assignment. The containers are non-limited so > that they can be composed. And that's because it doesn't make sense to have > limited elements (as the elements have to be copied into the container). On that subject, we recently had need of a bounded list (for restricted runtimes, sans dynamic memory allocation), something like: generic type ET is private; with "=" (L, R : ET) return Boolean is <>; package Ada.Containers.Bounded_Lists is type List (Capacity : Count_Type) is tagged limited private; ... -- more or less same as Doubly_Linked_Lists end; That brings up the composability issue, since you'd like to be able to create a container whose elements are bounded lists. I came up with something like: generic type ET is limited private; package Ada.Containers.Limited_Bounded_Lists is type List (Capacity : Count_Type) is tagged limited private; function Element (Container : not null access List; Position : Cursor) return not null access ET; function Constant_Element (Container : not null access constant List; Position : Cursor) return not null access constant ET; function First_Element (Container : not null access List) return not null access ET; function Constant_First_Element (Container : not null access constant List) return not null access constant ET; ... end; Query_Element and Update_Element are still there, but it's awfully nice to be able to rename an element directly. You can do something like: procedure Op (L : in out List) is begin L.Append (Initialize'Access); -- init elem -- or: L.Append; -- no init necessary -- or: L.Insert (Before => No_Element, Process => Initialize'Access); -- or: L.Insert (Before => No_Element); declare E : ET renames L.Last_Element; -- implicit 'Access begin ... -- use E end; end Op; The only potential issue is that if you rename an active element, it can subsequently become inactive (if you Delete it) in the scope of the renaming. If you were to subsequently manipulate it that would probably be bad, but at least the object doesn't disappear as it would in the unbounded case, since the object just moves onto an internal free list owned by the list. Don't know if that's the right thing to do, though. I haven't done anything with it yet so maybe I'll just get rid of those ops. It's just that in the case of a limited element, it's OK to declare the element as aliased, since there's no issue (I think) about constraining an element object whose type is a discriminated record with default discriminant. It was nice to be able to bounce ideas off of the ARG subcommittee. We ought to set up a mailing list or something to discuss post-Ada 2005 container issues. We might be able to reuse the old mailing list at yahoo if it's still around. -Matt