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, T_FILL_THIS_FORM_SHORT autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f7a9613bbc2bd8c9 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-05-13 08:20:14 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!fu-berlin.de!uni-berlin.de!pec-19-25.tnt6.hh2.uunet.DE!not-for-mail From: Dmitry A. Kazakov Newsgroups: comp.lang.ada Subject: Re: Generic default parameters Date: Mon, 13 May 2002 17:21:23 +0200 Message-ID: <60lvdu4ifauunm4qob6ir7rlas4soe0cp4@4ax.com> References: NNTP-Posting-Host: pec-19-25.tnt6.hh2.uunet.de (149.225.19.25) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: fu-berlin.de 1021303209 20935476 149.225.19.25 (16 [77047]) X-Newsreader: Forte Agent 1.8/32.548 Xref: archiver1.google.com comp.lang.ada:23962 Date: 2002-05-13T17:21:23+02:00 List-Id: On 13 May 2002 10:00:26 -0400, Stephen Leake wrote: >Dmitry A. Kazakov writes: > >> 7. Incomplete instantiations: >> >> package X is new Y (<>); >> -- >> -- No actual parameters given. >> -- All declarations of the visible part of X >> -- are incomplete here in usual sense. >> -- I.e. if X declares a a type XX then >> -- type XX_Ptr is access X.XX; >> -- would be OK. >> . . . >> private >> package X is new Y (); >> >> The formal parameters which actuals are not visible in the public >> part, shall be only used in the private part or the body of the >> generic. The idea is to instantiate a generic with some private things >> and yet to have the instance visible. > >This I'm less happy with. I think you can get the same effect with >library instantiations and/or child packages. I do not know how. Moreover I suppose that there should be no way, otherwise, "private" would be leaky, which we definitely do not want to have. A concrete example. Let we want to implement smart pointers / handles. It could go as follows: package Object is type Entity is new Ada.Finalization.Limited_Controlled with record Use_Count : Natural := 0; -- Reference count end record; ... end Object; generic type Object_Type (<>) is abstract new Entity with private; type Object_Type_Ptr is access all Object_Type'Class; package Object.Handle is type Handle is tagged private; ... private type Handle is new Ada.Finalization.Controlled with record Ptr : Object_Type_Ptr := null; end record; end Object.Handle; Now the problem, how to instantiate Object.Handle having Object_Type private? Let we have: package IO is ... private type File_Descriptor is new Entity with ...; type File_Descriptor_Ptr is access all File_Descriptor'Class; end IO; package IO.Handles is package Handles is new Object.Handle (File_Descriptor, File_Descriptor_Ptr); -- Illegal, File_Descriptor is not visible here subtype IO_Handle is Handles.Handle; ... end IO.Handles; If we move the instantiation into the private part it would work, but then it would be private. Once private, always private. With 7 it could be: package IO.Handles is package Handles is new Object.Handle (<>); subtype IO_Handle is Handles.Handle; ... -- Declaration of proxy operations on handles private package Handles is new Object.Handle (File_Descriptor, File_Descriptor_Ptr); end IO.Handles; --- Regards, Dmitry Kazakov www.dmitry-kazakov.de