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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,4608b6f4718e680f X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.231.2 with SMTP id tc2mr12195381pbc.8.1336416925178; Mon, 07 May 2012 11:55:25 -0700 (PDT) Path: pr3ni15364pbb.0!nntp.google.com!news1.google.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: ytomino Newsgroups: comp.lang.ada Subject: Re: Problem in "X (1).Re := X (1).Re + 1" Date: Mon, 7 May 2012 11:53:58 -0700 (PDT) Organization: http://groups.google.com Message-ID: <5749033.1275.1336416838264.JavaMail.geo-discussion-forums@pbchd7> References: <13177506.38.1336222539273.JavaMail.geo-discussion-forums@pbtg6> <21452734.731.1336405064187.JavaMail.geo-discussion-forums@ynbv35> NNTP-Posting-Host: 118.8.128.51 Mime-Version: 1.0 X-Trace: posting.google.com 1336416925 14851 127.0.0.1 (7 May 2012 18:55:25 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 7 May 2012 18:55:25 +0000 (UTC) In-Reply-To: <21452734.731.1336405064187.JavaMail.geo-discussion-forums@ynbv35> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=118.8.128.51; posting-account=Mi71UQoAAACnFhXo1NVxPlurinchtkIj User-Agent: G2/1.0 Content-Type: text/plain; charset=ISO-8859-1 Date: 2012-05-07T11:53:58-07:00 List-Id: On Tuesday, May 8, 2012 12:37:44 AM UTC+9, Adam Beneschan wrote: > > No. But if you change the 1 to 1.0 then I think it will be OK. Oops! 1.0 is correct. > I'm not yet really familiar with the ins and outs of user-defined references > and user-defined indexing. But my guess is that the phrase in A.18.2(147.17) > that says "Reference returns an object whose discriminant is an access value > that designates the element designated by Position" means that Reference > can't return an object whose discriminant designates a *copy* of the element. > If I understand your question correctly, this means that the scenario you're > concerned about can't happen. Imagine an implementation of an reference-counted container. Probably, it's like below: function Reference (Container : Vector; Position : Cursor) return Ref_Type is begin -- if data is shared, do copy-on-write to prepare for change -- (memory management and exclusive control is omitted in this pseudo-code) if Container.Data_Block.Ref_Count > 1 then Container.Data_Block.Ref_Count := Container.Data_Block.Ref_Count - 1; Container.Data_Block := new Data_Block_Type'( Length => Container.Data_Block.Length, Elements => (1 .. Length => Container.Data_Block.Elements (1 .. Length)), Ref_Count => 1); end if; -- return access value designated by Position return (Element => Container.Data_Block.Elements (To_Index (Cursor))'Access); end Reference; And, similar copy-on-write is inserted into Replace_Element and Update_Element. In this container, Reference copies its elements as your saying. But the container comes to own copied elements, and Reference returns an access value that designates the element in same area. I hope that this is allowed for effective implementations. Besides, if this is disallowed in Ada.Containers.Vectors, please assume my original container. Surely you don't think that all reference-counted containers written by user are forbidden to implement user-defined indexing.