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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.107.166.69 with SMTP id p66mr2179219ioe.85.1513688892414; Tue, 19 Dec 2017 05:08:12 -0800 (PST) X-Received: by 10.157.82.148 with SMTP id f20mr141882oth.2.1513688892301; Tue, 19 Dec 2017 05:08:12 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.kjsl.com!usenet.stanford.edu!g80no290334itg.0!news-out.google.com!b73ni1019ita.0!nntp.google.com!g80no290330itg.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 19 Dec 2017 05:08:11 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=173.71.208.22; posting-account=QF6XPQoAAABce2NyPxxDAaKdAkN6RgAf NNTP-Posting-Host: 173.71.208.22 References: <5b32a99e-04e5-4adb-8b42-88e485570641@googlegroups.com> <83982113-349e-4443-b457-e63d749ad42a@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Full view of a private partial view cannot be a subtype From: Jere Injection-Date: Tue, 19 Dec 2017 13:08:12 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader02.eternal-september.org comp.lang.ada:49535 Date: 2017-12-19T05:08:11-08:00 List-Id: On Tuesday, December 19, 2017 at 4:08:46 AM UTC-5, Dmitry A. Kazakov wrote: > On 2017-12-19 02:01, Jere wrote: > > On Sunday, December 17, 2017 at 10:39:17 AM UTC-5, Dmitry A. Kazakov wrote: > >> On 2017-12-17 16:26, Jere wrote: > >> > > Something like: > > > > generic > > type Item_Type(<>); > > type Item_Access is access Item_type; > > with procedure Deallocation(Ref : in out Item_Access); > > package Sledgehammer is > > > > > > private > > > > end Sledgehammer; > > > > This would be used in maybe 5% or less of the code base and only > > when absolutely necessary. I want to convert it to: > > > > generic > > type Item_Type(<>) is limited private; > > package Nicer_Package is > > type Item_Access is access Item_Type; > > > > > > private > > procedure Deallocate is new Ada.Unchecked_Deallocation > > (Item_Type,Item_Access); > > > > package Implementation is new Sledgehammer > > (Item_Type => Item_Type, > > Item_Access => Item_Access, > > Deallocation => Deallocate); > > > > > > end Nicer_Package; > > > > Since all I am doing is automating the access type and > > the deallocation operation, I don't think a new type > > is really the right design. Additionally, I don't want > > to expose the deallocation operation as it should never > > be called directly. > > How do you create objects? Explicit. The client does. It's mostly due to the need for of the incomplete type. I can't make or manage objects of type Item_Type, so the client has to allocate. > > There are two approaches: > > 1. Explicit new, implicit deallocate. This works only with containers, > which should know the access type and the deallocator. > > 2. Factory (a Create call), implicit deallocate. This requires reference > counting or custom GC pool. > > P.S., declaring an access type in the public part of a generic is > suspicious for bad design. > Again, it is only for basically to keep the client from having to specify in 90-95% of the situations where they don't really need it. The type is never used to create variables. In the more complex generic, I make the client specify instead, but the simpler one is just for quick utility and hopefully lack of exposure to the deallocation routine.