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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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!news2.google.com!news3.google.com!news.glorb.com!npeer.de.kpn-eurorings.net!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: limited types (Was: Records that could be arrays) Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.14.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <1cwl2r5h594du$.1q4kglbpb2bma.dlg@40tude.net> Date: Sun, 26 Feb 2006 21:52:32 +0100 Message-ID: <10ovc4gxk6wka.gttjb2v0fbcq$.dlg@40tude.net> NNTP-Posting-Date: 26 Feb 2006 21:52:22 MET NNTP-Posting-Host: 4784ffce.newsread2.arcor-online.net X-Trace: DXC=d==Q[6LHn;2LCV^[ On Sun, 26 Feb 2006 18:20:39 GMT, Matthew Heaney wrote: > "Dmitry A. Kazakov" writes: > >> 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++. No. The constructor is wrapped by the function. Differently to a true constructor, you cannot ensure the wrapper to be always called for some specified signature. > 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.) Consider the following use cases: 1. Containers of class-wide types (this will be possible.) 2. Subtypes of (1) constrained to a definite type from the class. 3. Containers of specific types building a parallel types hierarchy. I.e. if S is a subtype of T, then a container type with the elements of S is a subtype of a container type with the elements of T. >> 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 This you have to override in each of non-abstract derived type. If the compiler knew that Copy is a constructor it could safely compose it out of constructors of the bases and the components (in most of cases.) > function Copy_Classwide (E : ET'Class) return ET'Class is > begin > return Copy (E); -- legal Ada 2005? > end; I don't see why it should be illegal. But I wish the compiler to do this automatically. >> ... 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. And this is an argument? (:-)) Even if the functions were passed without pointers (as they should be in a language like Ada), even then it would be ugly, because the compiler and the reader of the code already have full information about what's going on. The type itself tells everything unambiguously. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de