From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Getting the index for an element in mutually referencing containers
Date: Mon, 13 Mar 2017 21:53:07 +0100
Date: 2017-03-13T21:53:07+01:00 [thread overview]
Message-ID: <oa70rj$12td$1@gioia.aioe.org> (raw)
In-Reply-To: oa6teu$r7$1@franka.jacob-sparre.dk
On 2017-03-13 20:55, Randy Brukardt wrote:
> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> 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
next prev parent reply other threads:[~2017-03-13 20:53 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-09 13:45 Getting the index for an element in mutually referencing containers Mart van de Wege
2017-03-09 15:25 ` Egil H H
2017-03-09 15:45 ` Mart van de Wege
2017-03-09 16:02 ` Mart van de Wege
2017-03-09 16:11 ` Egil H H
[not found] ` <ly7f3xedp4.fsf@pushface.org>
[not found] ` <86k27xpikd.fsf@gaheris.avalon.lan>
[not found] ` <lywpbxc9my.fsf@pushface.org>
[not found] ` <86wpbxneuz.fsf@gaheris.avalon.lan>
[not found] ` <o9vcbp$t0t$1@franka.jacob-sparre.dk>
2017-03-11 6:45 ` Mart van de Wege
2017-03-11 8:40 ` Simon Wright
2017-03-11 8:58 ` Dmitry A. Kazakov
2017-03-11 11:21 ` Simon Wright
2017-03-11 14:18 ` Dmitry A. Kazakov
2017-03-11 20:05 ` Simon Wright
2017-03-11 20:52 ` Dmitry A. Kazakov
2017-03-11 21:46 ` Simon Wright
2017-03-11 22:37 ` Niklas Holsti
2017-03-12 8:22 ` Simon Wright
2017-03-12 9:38 ` G.B.
2017-03-12 11:21 ` Simon Wright
2017-03-13 10:29 ` Alejandro R. Mosteo
2017-03-12 8:20 ` Dmitry A. Kazakov
2017-03-12 11:30 ` Simon Wright
2017-03-12 11:55 ` Dmitry A. Kazakov
2017-03-12 16:44 ` Simon Wright
2017-03-12 17:42 ` Dmitry A. Kazakov
2017-03-13 19:55 ` Randy Brukardt
2017-03-13 20:53 ` Dmitry A. Kazakov [this message]
2017-03-14 20:40 ` Randy Brukardt
2017-03-15 8:44 ` Dmitry A. Kazakov
2017-03-15 20:12 ` Randy Brukardt
2017-03-16 2:59 ` Paul Rubin
2017-03-16 9:04 ` Dmitry A. Kazakov
2017-03-13 23:25 ` Simon Wright
2017-03-14 8:25 ` Dmitry A. Kazakov
2017-03-12 1:36 ` Randy Brukardt
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox