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,b553d2c02a2df59f X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news3.google.com!news.glorb.com!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!stamper.news.atl.earthlink.net!newsread2.news.atl.earthlink.net.POSTED!14bb18d8!not-for-mail Sender: Matthew Heaney@MHEANEYIBMT43 Newsgroups: comp.lang.ada Subject: Re: limited types (Was: Records that could be arrays) References: <1cwl2r5h594du$.1q4kglbpb2bma.dlg@40tude.net> From: Matthew Heaney Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Sun, 26 Feb 2006 18:20:39 GMT NNTP-Posting-Host: 24.149.57.125 X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.news.atl.earthlink.net 1140978039 24.149.57.125 (Sun, 26 Feb 2006 10:20:39 PST) NNTP-Posting-Date: Sun, 26 Feb 2006 10:20:39 PST Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: g2news1.google.com comp.lang.ada:3172 Date: 2006-02-26T18:20:39+00:00 List-Id: "Dmitry A. Kazakov" writes: > On Sat, 25 Feb 2006 15:05:02 GMT, Matthew Heaney wrote: > > > But you can pass in an Initialize procedure as a parameter of an insertion > > operation, to perform whatever initialization needs to be done. > > You mean "return .. do" for limited types. For an unbounded form, you could do it either way, via an Initialize procedure, or via a Copy function (using the new return do syntax). For a bounded form, only an Initialize procedure would work, since the actual initialization of the elements happens only once, when the (bounded) container object is elaborated. > It is in-place, but a constructing function does not have safety of a > constructor. Huh? An Ada 2005 constructor function *is* a constructor. It's no different from a copy ctor in C++. > Then you cannot ask it from the type, so it can't have a default > [deduced from the type.]. It is not dispatching in Insert. Aren't constructors always non-dispatching (unless you're using a Factory Method pattern)? But this is no different from the C++ STL. If you have an container (of indefinite elements) instantiated with (limited) type T'Class, then I suppose you might want to have a dispatching constructor. I'd have to think about how to do that[but see below]. (In my earlier example I was really thinking of bounded forms, which cannot have indefinite elements.) > What about container of class-wides, i.e. when Node_Type should have > ET'Class? Only applies to unbounded containers whose elements are indefinite. GCC allocates each indefinite element (so Node_Type has a pointer to ET). In general there's never any direct dispatching inside a generic, since the generic formal region doesn't pass in any operations, the formal type isn't tagged, and formal operations must be statically bound to the element type. If you wanted a contructor to dispatch, you'd have to say (assuming my knowledge of Ada 2005 is correct): type ET is tagged limited private; function Copy (E : ET) return ET; -- primitive op function Copy_Classwide (E : ET'Class) return ET'Class is begin return Copy (E); -- legal Ada 2005? end; Then you pass this in as per the example of my earlier post: package List_Types is new Limited_Indefinite_Lists (ET'Class); ... procedure Op (L : in out List) is begin ... L.Insert (...New_Item => E, Copy => Copy_Classwide...); ... end; Then the primitive Copy operation will dispatch according to the tag of actual parameter E. This is always what you do inside a generic to enable dispatching (when the generic formal type is non-tagged and indefinite). > ... and of course passing pointers to functions is ugly. This is not an argument. The existing API already has function pointers everywhere, so you might as well get used to it.