comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Indefinite Containers of Indefinite Private Types
Date: Fri, 7 Aug 2015 13:45:24 -0700
Date: 2015-08-07T13:45:24-07:00	[thread overview]
Message-ID: <mq35a3$9kv$1@dont-email.me> (raw)
In-Reply-To: <87a8u2luvy.fsf@theworld.com>

On 08/07/2015 01:13 PM, Bob Duff wrote:
> "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org> writes:
> 
>> Yes, of course. The examples are simplified from a more complex case where the
>> container is used in the full type definition. This can be achieved by adding
>> some additional code that is essentially noise, or by using access types.
>> Avoiding access types is worth adding noise, but it would be nice if the noise
>> were unnecessary.
> 
> I'm curious what the "noise" looks like in your case.
> 
> Last time I ran into this problem I think I ended up using a workaround
> that involved access types.  I don't remember the details.

It involves using tagged types, type extension, and a container of a class-wide
type:

with Ada.Containers.Indefinite_Vectors;

package P is
   type T (<>) is private;
private
   type Root is tagged null record;

   package Lists is new Ada.Containers.Vectors
      (Index_Type => Positive, Element_Type => Root'Class);

   type T is new Root with record
      List : Lists.Vector;
   end T;
end P;

The only reason for the type extension is to get the instantiation that can be
used in the full declaration of T. The only objects that will be stored in a
vector are of type T. In addition to the noise of the Root type and the
extension for T, there are type conversions required that are part of the noise.

-- 
Jeff Carter
"From this day on, the official language of San Marcos will be Swedish."
Bananas
28


      reply	other threads:[~2015-08-07 20:45 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-04  2:23 Indefinite Containers of Indefinite Private Types Jeffrey R. Carter
2015-08-04  5:40 ` Niklas Holsti
2015-08-04 18:56   ` Jeffrey R. Carter
2015-08-04 20:47     ` Randy Brukardt
2015-08-04 20:56       ` Jeffrey R. Carter
2015-08-06 18:49         ` Randy Brukardt
2015-08-06 20:12           ` Jeffrey R. Carter
2015-08-07 19:49             ` Randy Brukardt
2015-08-07 20:13     ` Bob Duff
2015-08-07 20:45       ` Jeffrey R. Carter [this message]
replies disabled

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