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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.unit0.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Ada Alternatives to Unrestricted_Access Date: Tue, 13 Mar 2018 09:46:14 +0200 Organization: Tidorum Ltd Message-ID: References: <4ab69a18-5766-446c-85c2-14e094199c95@googlegroups.com> <6792fcd7-a25a-417c-b45a-1a17b0168234@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net Pc+5zkrSaQmyd4WebpjGVwPj00zOsC3ajUfIccDYAPE62bUeVK Cancel-Lock: sha1:kReKgZ1U78L0ymu+6FXQKb2asco= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 In-Reply-To: Xref: reader02.eternal-september.org comp.lang.ada:50953 Date: 2018-03-13T09:46:14+02:00 List-Id: On 18-03-13 01:30 , Randy Brukardt wrote: > One easy way to get a rewritable reference of a controlled type is to save > it in the Initialize routine (note that the argument of Initialize is "in > out"). So you could have something like: > > type Container is tagged; > type Acc_Container is access all Container; > type Container is new Controlled with record > Self : Acc_Container; > end record; > > procedure Initialize (Obj : in out Container) is > begin > Obj.Self := Obj'Access; > end Initialize; > > And then you can use "Self" anytime you need to write the container object. A note, just to remind myself and others: for a non-limited Container type this "Self" component must also be updated (in fact restored to its Initialized value) in the Adjust operation. Otherwise, if A and B are Container objects, after A := B the component A.Self would access B. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .