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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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!news.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: How to declare a generic formal type "covered" by another? Date: Fri, 2 May 2014 17:33:45 +0200 Organization: cbb software GmbH Message-ID: <1dnxemiiras21.1p85n74xnxy38.dlg@40tude.net> References: <21e0e1f0-3fe4-4c5a-8e01-21691a0207f4@googlegroups.com> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: AuYlnUSfTZrfhAkRjyySpQ.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:19644 Date: 2014-05-02T17:33:45+02:00 List-Id: On Fri, 02 May 2014 08:12:01 -0700, Jeffrey Carter wrote: > One can create a safe-pointer package that does not expose an access type (see > the PragmAda Reusable Components for an example), but the result tends to be > restricted to pointers to definite, non-limited types. Safe-pointers do make much sense only with definite and non-limited types. I pass the pointer type to the package of safe pointers. It also gives an opportunity to have it pool-specific, when necessary. Yes, the object is allocated on the client side, e.g. Handle.Set (new Object (...constraints...)); -- [*] with Ada 2005 one could hide passed type returning anonymous access and using limited return constructing function. Though, as experience shows, it does not work well, especially the latter. ---- * This is a simplification, of course. If the object cannot be fully initialized per Initialize. It looks like: declare Ptr : Object_Ptr := new Object (...); Thing : Object'Class renames Ptr.all; begin Handle.Set (Ptr); ... -- Initialize Thing end; I wished Ada had a syntax to access allocated objects through class-wide pointers. Something like: ... new X : Object (...) ... do -- In this scope X refers to the allocated Object end new; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de