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!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: Smart pointers and delegation Date: Tue, 8 Aug 2017 08:27:15 +0200 Organization: Aioe.org NNTP Server Message-ID: References: NNTP-Posting-Host: MajGvm9MbNtGBKE7r8NgYA.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 Content-Language: en-US X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:47647 Date: 2017-08-08T08:27:15+02:00 List-Id: On 2017-08-08 00:39, Randy Brukardt wrote: > "Dmitry A. Kazakov" wrote in message > news:om3vsc$jhk$1@gioia.aioe.org... >> Let I want to pass R to an operation F of X. This should lock/unlock on >> the way. I cannot do that without some third type. > > Right. And that's a problem how? Helper types are quite common in ADTs. Everything is wrong. Helper type indicates language design problem. Each and every type must reflect some entity in the problem space. Helper type, as the name suggests, reflects a language problem instead. >> Implicit dereferencing semantically does the same. For each visible >> operation of the target type it declares an anonymous operation of the >> reference type that dereferences and then calls to the original operation. > > I don't see this at all. You do it with the eyes closed... (:-)) >> Smart pointers use the opposite approach. Pointers (the last one) outlive >> the targets. If a container is built then out of smart pointers, e.g. it >> keeps pointers to the elements. Alternatively, it can keep raw elements >> and hold a reference to each. You access elements strictly through >> pointers which need not to be disposed immediately. They can live as long >> as necessary. It can be used in transactional schemes, e.g. cloning >> elements for mutators if the reference count > 1 etc. > > It's not really opposite, though, if you want to limit the lifetime of the > reference (even if that limit is potentially a long time). Why would I want this, if the reference manages the object? The cardinal difference is between object-managed references and reference-managed objects. The former has a very limited use and would prefer to have all of them built-in. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de