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 Tagged Type Hierarchies Date: Tue, 1 Aug 2017 09:36:03 +0200 Organization: Aioe.org NNTP Server Message-ID: References: <2017072417413775878-contact@flyx.org> 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:47546 Date: 2017-08-01T09:36:03+02:00 List-Id: On 2017-08-01 05:43, Randy Brukardt wrote: > "Felix Krause" wrote in message > news:2017072417413775878-contact@flyx.org... > ... >> A problem I encounter is how this can be used with type hierarchies i.e. I >> have a smart pointer managing a tagged type, and I want to be able to >> derive from that tagged type and still be able to use my smart pointer >> with that new type. > > What's needed is something like "co-derivation", where multiple types are > derived in lock-step. Sadly, this is effectively impossible in an OOP > environment, because dispatching calls would have the wrong parameter types > for any co-derived types. (I've spent quite a bit of effort in trying to > make such a solution work, and have enlisted others to help, but the > conclusion was that it wasn't promising.) > > One would have to have some form of multiple dispatch to get around that, > but that's a bridge too far for a language that's mainly used in embedded, > safety-critical systems. But Ada already has this form of multiple-dispatch. The issue does not requires two types. Two controlling parameters of the same type is just enough: type T is tagged ... procedure Foo (X, Y : T); type S is new T with ... overriding procedure Foo (X, Y : S); X : T'Class := T'(...); Y : T'Class := S'(...); begin Foo (X, Y); So I would not be much concerned about that. Specifically for smart pointers we also need sliding access to co-type upon derivation. One could think of it as a constraint: type Pointer_Type (Target_Class : Tag ???) is record Ptr : access Target_Type'Class with Subclass => Target_Class; end record; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de