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, T_FILL_THIS_FORM_SHORT autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Getting the index for an element in mutually referencing containers Date: Mon, 13 Mar 2017 21:53:07 +0100 Organization: Aioe.org NNTP Server Message-ID: References: <86o9xa36oq.fsf@gaheris.avalon.lan> <86k27xpikd.fsf@gaheris.avalon.lan> <86wpbxneuz.fsf@gaheris.avalon.lan> NNTP-Posting-Host: BYuA7L7MRjuLLjcoGHOBxw.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:29418 Date: 2017-03-13T21:53:07+01:00 List-Id: On 2017-03-13 20:55, Randy Brukardt wrote: > "Dmitry A. Kazakov" wrote in message > news:oa41a4$1ko5$1@gioia.aioe.org... >> On 2017-03-12 17:44, Simon Wright wrote: > ... >> P.S. It is a pity that Implicit_Dereference type does not have proper >> interface to work with *any* type instead of discriminated records. This >> is design fault when the use case #2 was taken for #1. > > It works with any type, since the real target type is the thing designated > by the discriminant. The discriminant is the key, because it is the only way > in Ada to get an access type with a controlled lifetime. The discriminated > type is just a helper, not the end result. That would be the case #1 with *no* helper type whatsoever: type Element ... type Index ... type Container ... function Get (X : Container; I : Index) return Element; for Container'Get_Element use Get; function Get (X : Container; I : Index) return access Element; for Container'Access_Element use Get; etc > Yes, we could have done that some other way, There is no other way, there is another use case #2, when a reference object is required to live longer. That should be *any* type: type Reference_Type is private; private function Get (X : Reference_Type) return access Element; for Reference_Type'Implicit_Conversion (Element) use Get; of course it should be inheritance from Element in a better world: type Reference_Type is new Element; private function To_Element (X : Reference_Type) return Element; for Reference_Type'Upcast_Conversion use To_Element; by reference: type Reference_Type is new access Element; private function To_Element (X : Reference_Type) return access Element; for Reference_Type'Upcast_Conversion use To_Element; > and indeed we started with a > separate construct, but the semantics ended up identical to that of an > access discriminant of a controlled type -- so why build another construct > (with all of the additional chances of getting it wrong) when an existing > one will do? Because it gets everything wrong in the major use case #2. You need invalidated reference types. A pointer when explicit cannot be discriminant and furthermore there might be a pool-specific pointer or no pointer at all. And nobody wants to expose pointers under no circumstances anyway. When pointers are exposed any shred of safety is gone. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de