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=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 Path: g2news2.google.com!postnews.google.com!l18g2000yql.googlegroups.com!not-for-mail From: "Prof. Dr. Carl Weierstrass" Newsgroups: comp.lang.ada Subject: Re: Use of abstract tagged types without access types -- again and complete Date: Fri, 10 Jun 2011 08:43:45 -0700 (PDT) Organization: http://groups.google.com Message-ID: <63c5c60a-ba75-4ab4-afb3-b78aead48815@l18g2000yql.googlegroups.com> References: <53347692-e182-4f2f-8598-453af64e16fc@w36g2000vbi.googlegroups.com> <87hb7yn4fs.fsf@ludovic-brenta.org> NNTP-Posting-Host: 91.34.63.109 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1307720625 26426 127.0.0.1 (10 Jun 2011 15:43:45 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 10 Jun 2011 15:43:45 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: l18g2000yql.googlegroups.com; posting-host=91.34.63.109; posting-account=5zx--goAAAD06H29EnWQGKTO-gctuXHl User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: HUALESNKRC X-HTTP-UserAgent: Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1,gzip(gfe) Xref: g2news2.google.com comp.lang.ada:20706 Date: 2011-06-10T08:43:45-07:00 List-Id: 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: > >> =A0 =A0type Parent_Type is new Ada.Finalization.Controlled with record > >> =A0 =A0 =A0 =A0 =A0Child : Child_Type'Class; > >> =A0 =A0end 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. =A0The reason is that the size of Child is unknown, so you cannot > > encapsulate a Child into a Parent_Type, which has a fixed size. =A0In > > 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 does= n't > have to be visible. > > Specifically, use the Holder container for this purpose: > > =A0 =A0 =A0package Child_Holder is new Ada.Containers.Indefinite_Holders > (Child_Type'Class); > > =A0 =A0 =A0type Parent_Type is new Ada.Finalization.Controlled with recor= d > =A0 =A0 =A0 =A0 =A0 =A0Child : Child_Holder.Holder; > =A0 =A0 =A0end 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 (i= t > 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. > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0Randy. 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. Regards