comp.lang.ada
 help / color / mirror / Atom feed
From: Jere <jhb.chat@gmail.com>
Subject: Re: Full view of a private partial view cannot be a subtype
Date: Tue, 19 Dec 2017 05:08:11 -0800 (PST)
Date: 2017-12-19T05:08:11-08:00	[thread overview]
Message-ID: <f8490e31-96ab-42fe-b4cf-f505444f591e@googlegroups.com> (raw)
In-Reply-To: <p1akur$d4l$1@gioia.aioe.org>

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
> >     <types>
> >     <operations>
> > private
> >     <implementation>
> > 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;
> >     <same types>
> >     <same operations>
> > 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);
> > 
> >     <implementation>
> > 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.


  reply	other threads:[~2017-12-19 13:08 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-03  2:14 Full view of a private partial view cannot be a subtype Jere
2017-12-03 12:01 ` Jeffrey R. Carter
2017-12-03 13:33   ` Jere
2017-12-03 14:34     ` Jeffrey R. Carter
2017-12-03 17:44       ` Robert Eachus
2017-12-03 18:50         ` Simon Wright
2017-12-03 22:10           ` Robert Eachus
2017-12-03 19:03         ` Jeffrey R. Carter
2017-12-03 22:23       ` Jere
2017-12-04  8:25         ` Dmitry A. Kazakov
2017-12-04 18:04         ` Jeffrey R. Carter
2017-12-04 20:41           ` Jere
2017-12-04 21:48             ` Jeffrey R. Carter
2017-12-05  8:20               ` Dmitry A. Kazakov
2017-12-05 18:16                 ` Jeffrey R. Carter
2017-12-05 20:39                   ` Dmitry A. Kazakov
2017-12-05 21:38                     ` Jeffrey R. Carter
2017-12-05 12:35               ` Jere
2017-12-05 18:40                 ` Jeffrey R. Carter
2017-12-06 12:54                   ` Jere
2017-12-06 18:03                     ` Jeffrey R. Carter
2017-12-05 20:22                 ` Randy Brukardt
2017-12-05 15:27               ` Shark8
2017-12-05 18:50                 ` Jeffrey R. Carter
2017-12-05 20:59                 ` Randy Brukardt
2017-12-05 22:43                   ` Shark8
2017-12-07  0:52                     ` Randy Brukardt
2017-12-05 20:16               ` Randy Brukardt
2017-12-05 21:29                 ` Jeffrey R. Carter
2017-12-07  0:04                   ` Randy Brukardt
2017-12-04 20:49 ` Randy Brukardt
2017-12-05 12:56   ` Jere
2017-12-05 20:12     ` Randy Brukardt
2017-12-17 15:26       ` Jere
2017-12-17 15:39         ` Dmitry A. Kazakov
2017-12-18 22:47           ` Randy Brukardt
2017-12-19  1:22             ` Jere
2017-12-19 23:16               ` Randy Brukardt
2017-12-19  1:01           ` Jere
2017-12-19  9:08             ` Dmitry A. Kazakov
2017-12-19 13:08               ` Jere [this message]
2017-12-19 13:27                 ` Dmitry A. Kazakov
2017-12-19 19:10             ` Stephen Leake
2017-12-18 20:45 ` Stephen Leake
2017-12-18 22:54   ` Randy Brukardt
2017-12-19  1:08   ` Jere
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox