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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1c4bf3a1bd5d40f3 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-11-08 12:49:10 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: mheaney@on2.com (Matthew Heaney) Newsgroups: comp.lang.ada Subject: Re: Booch: missing r/w access through iterators Date: 8 Nov 2002 12:49:10 -0800 Organization: http://groups.google.com/ Message-ID: <1ec946d1.0211081249.68cf4d7b@posting.google.com> References: <3dc92622$0$308$bed64819@news.gradwell.net> <3dc9ec63$0$300$bed64819@news.gradwell.net> NNTP-Posting-Host: 66.162.65.162 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1036788550 8229 127.0.0.1 (8 Nov 2002 20:49:10 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 8 Nov 2002 20:49:10 GMT Xref: archiver1.google.com comp.lang.ada:30608 Date: 2002-11-08T20:49:10+00:00 List-Id: Simon Wright wrote in message news:... > porton@ex-code.com (Victor Porton) writes: > > I can see why you might want it, and at the moment I can't remember > why it's not there. Perhaps something to do with the problem of > creating the access value? (it would force the item in the Container > to be aliased, thus constraining it .. I know this actually happens in > the BCs but I was very unhappy with the necessary kluge). Simon is correct that the elements in the container will have to be aliased. If you have an element type that is an definite, unconstrained record, like this: type DT is (A, B, C); type RT (D : DT := DT'First) is record ... end record; then the simplest thing to do is wrap this in another record: type Element_Type is record R : RT; end record; and then instantiate the component with the wrapper type: package Set_Types is new Charles.Sets.Unbounded (Element_Type, ...); Now you can do this to get at the element: type Element_Access is access all Element_Type; function To_Access is new Generic_Element (Element_Access); declare E : Element_Type renames To_Access (Iterator).all; begin end; The Charles library is available at my home page: http://home.earthlink.net/~matthewjheaney/charles/index.html The reason this restriction exists is because of access subtypes. For example, given our discriminated record type above, we can do this: type R_Access is access RT; subtype RA_Access is R_Access (A); The issue is that if you have this: RA : RA_Access := new RT'(D => A, ...); then you always have a guarantee that the discriminated record object designated by access object RA always has a discriminant with the value DT'(A). You're not allowed to change the discriminant of an aliased unconstrained discriminated record, because that would break the guarantee. This is arguably a flaw in the language. The type model is consistent in that you it supports subtypes of types, but extending that model to include access types too was probably too much of a good thing. The problem is that you need an aliased unconstrained discriminated record a lot more often than you need an access subtype. Hence the problem to which Simon was refering.