From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Smart pointers and delegation
Date: Fri, 11 Aug 2017 15:37:39 -0500
Date: 2017-08-11T15:37:39-05:00 [thread overview]
Message-ID: <oml4ik$pmh$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: omjjlr$1ia7$1@gioia.aioe.org
"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
news:omjjlr$1ia7$1@gioia.aioe.org...
> On 2017-08-11 02:17, Randy Brukardt wrote:
...
>>> My design of containers is that I effectively put a reference in the
>>> form
>>> of a smart pointer into the container. I don't need return by reference
>>> because I return a smart pointer, which is definite and non-limited. I
>>> have no problem with life time because the reference holds the object. I
>>> less problems with concurrent updates because the reference has a count
>>> so
>>> that the update may deploy a transaction scheme. And I tend to hide the
>>> referenced object type from public interface to make it more safe.
>>
>> Not sure I see how a "smart pointer" would work in this context. I could
>> imagine some sort of handle working if you don't need partial, in-place
>> updates.
>
> Partial updates work because there an explicit operation to get plain
> access type:
>
> A (I).Ptr.C := Y; -- [*]
>
> But I don't like this sort of things anyway.
That's good, because a "plain access type" is dangerous (it has a global
lifetime if defined in an ADT). Thus it very easily becomes dangling. If all
you want is something for dereferences, you have to use an anonymous access
discriminant and a call-back when done, which is the normal usage pattern of
Implicit_Dereference (of course, you can do that without using
Implicit_Dereference if you don't mind the extra text as in the above
assignment).
> So usually it is a setter defined on the handle:
>
> A (I).Set_C (Y);
That's better, but of course requires a setter for every component. Which
necessarily merges the container and the element.
...
> -----------------------------
> * I really do not understand why Implict_Dereference has this ugly form
> instead of simply declaring that type P is a user implementation of
> access-to-T type with user operation to provide access-to-T result. BTW, a
> type can be both access-to-T and access-to-V. Why not? But this is another
> story because smart pointers need not to be access, not visibly.
"Simply"? Not much of anything is "simply" in language terms.
Implicit_Dereference is relatively simple in language terms because it is
mainly defined in terms of a text equivalence (thus, few rules have to be
repeated). I doubt anyone would argue that it is simple in usage terms; the
theory was that few would care about the details of setting it up, since the
vast majority would just use it in a container. That's very much like the
theory behind generics. (And yes, I doubt you would agree with that theory
in either case.)
No one suggested an idea like the one you gave here, so it certainly was not
considered. But typically, ambiguity in a type declaration causes problems
elsewhere. Types are the one thing in Ada that really provide an anchor:
they can't be overloaded, they always have a single meaning (at a particular
point in the text, it could change from visibility but nothing else), and so
on. Changing that might be problematical. But someone would have to do a
full analysis to be sure, and it is too late for that now.
Randy.
prev parent reply other threads:[~2017-08-11 20:37 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-01 10:32 Smart pointers and delegation Dmitry A. Kazakov
2017-08-01 15:06 ` Dmitry A. Kazakov
2017-08-01 23:06 ` Randy Brukardt
2017-08-02 6:20 ` Dmitry A. Kazakov
2017-08-03 3:36 ` Randy Brukardt
2017-08-03 7:40 ` Dmitry A. Kazakov
2017-08-04 23:03 ` Randy Brukardt
2017-08-05 8:33 ` Dmitry A. Kazakov
2017-08-07 22:39 ` Randy Brukardt
2017-08-08 6:27 ` Dmitry A. Kazakov
2017-08-09 0:27 ` Randy Brukardt
2017-08-09 7:37 ` Dmitry A. Kazakov
2017-08-09 22:57 ` Randy Brukardt
2017-08-10 7:56 ` Dmitry A. Kazakov
2017-08-11 0:17 ` Randy Brukardt
2017-08-11 6:43 ` Dmitry A. Kazakov
2017-08-11 20:37 ` Randy Brukardt [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox