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!news2.google.com!news4.google.com!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!stamper.news.atl.earthlink.net!newsread3.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> <10ovc4gxk6wka.gttjb2v0fbcq$.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 22:07:00 GMT NNTP-Posting-Host: 24.149.57.125 X-Complaints-To: abuse@earthlink.net X-Trace: newsread3.news.atl.earthlink.net 1140991620 24.149.57.125 (Sun, 26 Feb 2006 14:07:00 PST) NNTP-Posting-Date: Sun, 26 Feb 2006 14:07:00 PST Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: g2news1.google.com comp.lang.ada:3174 Date: 2006-02-26T22:07:00+00:00 List-Id: "Dmitry A. Kazakov" writes: > On Sun, 26 Feb 2006 18:20:39 GMT, Matthew Heaney wrote: > > 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 will always be called for some > specified signature. This is a specious argument. If you says the "real" constructor is wrapped by a function then you're guilty of moving the goal-posts. We're talking about requiring that a constructor be called. The syntax doesn't matter. That fact that Ada 2005 spells it f-u-n-c-t-i-o-n is irrelevent. If you want to force a constructor to be used, then you can make the partial view of the type indefinite. > Consider the following use cases: > > 1. Containers of class-wide types (this will be possible.) Yes, you already have this. > 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. You have totally misunderstood the design of the Ada 2005 container library. When you use cursors, then this abstracts-away the container itself, leaving you with a sequence of elements. This model works for all the containers already (and for arrays too, in fact). Write your algorithms in terms of sequences of elements instead of containers, and you can forget about containers. > > 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. Not quite. You have to override only if this is a non-null extension. But again that's no different from C++. Derived classes need to implement their own ctor, if only to call the ctor of the base class. (In the typical case, the base class is abstract, and its ctor is declared as protected. The ctor available to users is the ctor of the derived class.) > 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.) In practice concrete derived classes must implement their own ctors, that call the ctor of the base class. > > 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. But I did this to show you how call a dispatching operation inside a generic, with a non-tagged indefinite formal type. It's completely consistent with the existing generic model. When are operations for generic formal private types ever just synthesized? In the case at hand, you need an operation that takes type ET'Class, which is the type used to instantiate the generic, so you have to write it yourself, the same as for any other operation. > And this is an argument? (:-)) This ignores the history of Ada language evolution: Ada83: no function pointers; royal pain Ada95: function pointers at library-level only: GUI callbacks, etc Ada05: function pointers in nested scopes too No one seems to agree with you, Dmitry! The trend has been to allow the declaration of "ugly" function pointers in more places, not fewer.