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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,bb06c19745c6aacb X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: "Alex R. Mosteo" Newsgroups: comp.lang.ada Subject: Re: Use of abstract tagged types without access types -- again and complete Followup-To: comp.lang.ada Date: Sun, 12 Jun 2011 14:05:09 +0200 Organization: A noiseless patient Spider Message-ID: References: <53347692-e182-4f2f-8598-453af64e16fc@w36g2000vbi.googlegroups.com> <87hb7yn4fs.fsf@ludovic-brenta.org> <63c5c60a-ba75-4ab4-afb3-b78aead48815@l18g2000yql.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit Injection-Date: Sun, 12 Jun 2011 12:05:10 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="GE1qkKi7N8YRsc1w8M9Vdw"; logging-data="5094"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18tFBagamYnhziYT7HiRU2i" User-Agent: KNode/4.4.10 Cancel-Lock: sha1:cUe6bAb2dHb0l1jdnSR6EMcosKE= Xref: g2news1.google.com comp.lang.ada:19774 Date: 2011-06-12T14:05:09+02:00 List-Id: Prof. Dr. Carl Weierstrass wrote: > On 9 Jun., 23:06, "Randy Brukardt" wrote: >> "Ludovic Brenta" wrote in message >> >> news:87hb7yn4fs.fsf@ludovic-brenta.org... >> >> > "Prof. Dr. Carl Weierstrass" writes on comp.lang.ada: >> >> type Parent_Type is new Ada.Finalization.Controlled with record >> >> Child : Child_Type'Class; >> >> end record; >> >> >> This doesn't work, because: >> >> class-wide subtype with unknown discriminants in component declaration >> >> >> Of course I could use an access type to avoid the error but is there a >> >> way to do something like this without access types. >> >> > No. The reason is that the size of Child is unknown, so you cannot >> > encapsulate a Child into a Parent_Type, which has a fixed size. In >> > contrast, the size of an access value is fixed at comile time, so you >> > can encapsulate an access value in the Parent_Type. >> >> Not quite accurrate -- an access type is necessary somewhere, but it >> doesn't have to be visible. >> >> Specifically, use the Holder container for this purpose: >> >> package Child_Holder is new Ada.Containers.Indefinite_Holders >> (Child_Type'Class); >> >> type Parent_Type is new Ada.Finalization.Controlled with record >> Child : Child_Holder.Holder; >> end record; >> >> This is a slight complication when using the component (you have to use >> Element and Replace_Element to access the contents), but it is usually >> better than writing all of this storage management yourself. >> >> The only downside is whether your Ada compiler supports this container >> (it was added after Ada 2005 was finished, early in the Ada 2012 >> process). It's used in the latest ASIS (that's why it was invented), so a >> compiler supporting ASIS for Ada 2005 probably supports the container. >> >> If your compiler doesn't yet support this container, it's easy enough to >> create it yourself rather than using explicit access types. >> >> Randy. > > Thank you very much. I think that this could be the solution that I > was looking for. > In case of many children I considered using an > Ada.Containers.Indefinite_Vectors type, > but I was looking for a solution when the is only one child. > Unfortunately I'am using > GNAT GPL 2010 and can't find that container in the library. > > Any idea, where I can find an implementation? I hope it will be in the > next GNAT GPL 2011 > version. I've been using this 'holder' approach for years. If you don't have the official, the simplest way is to make your own with any other of the standard containers, and a simplified spec. Migration to the true Holder would later be a matter of seconds with a single search/replace if you take care to respect the subprogram names. > > Regards