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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d2f0af5e440b367f X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-07-13 18:36:08 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!newshub.sdsu.edu!elnk-pas-nf2!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!stamper.news.atl.earthlink.net!harp.news.atl.earthlink.net!not-for-mail From: Richard Riehle Newsgroups: comp.lang.ada Subject: Re: proposal for new assignment operators Date: Sun, 13 Jul 2003 18:39:27 -0700 Organization: AdaWorks Software Engineering Message-ID: <3F1209CF.C3907A61@adaworks.com> References: <3EF9CD5F.6030608@cogeco.ca> <3doRhIgUmUYX@eisner.encompasserve.org> <3F038B77.2F2E41B7@adaworks.com> <1ec946d1.0307070736.2eb5e820@posting.google.com> Reply-To: richard@adaworks.com NNTP-Posting-Host: 3f.bb.a0.d5 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Server-Date: 14 Jul 2003 01:36:07 GMT X-Mailer: Mozilla 4.7 [en] (Win98; I) X-Accept-Language: en Xref: archiver1.google.com comp.lang.ada:40247 Date: 2003-07-14T01:36:07+00:00 List-Id: Matthew Heaney wrote: > Richard Riehle wrote in message news:<3F038B77.2F2E41B7@adaworks.com>... > > > > One reason for the peculiarity is that Ada, unlike C++, has limited > > types. For limited types, assignment is never possible. Therefore, > > overloading assignment is not possible. Limited types are used for > > most container classes. > > The statement that C++ doesn't have limited types is false. To make a > limited type in C++, you simply have to declare the assignment > operator and copy constructor as private, and not define them: > > class Limited_Type is > public: > void f(); > private: > Limited_Type& operator=(const Limited_Type&); > Limited_Type(const Limited_Type&); > }; Limited types are not defined as part of the C++ standard. One can, of course, do as you have with your example. I rather doubt it is as common as one would find in Ada. > Also, most container types are not limited, because containers that > are limited are hard to compose. (It should be easy to instantiate a > container type using another container type as the element type.) Container types, perhaps not those you have created, are often designed as limited types. There are different points-of-view on this. I recall a PhD dissertation from OSU on this subject where the dissertation recommended that all types for a container be limited, even the generic formal parameters. > The reason you need non-limited types is for composition, not for > assignment (which has dubious value for a container). There are many > ways to copy a container without using the assignment operator. Of course, the idiom for composing with a limited type involves a generic formal access type parameter. Recall the wonderful quote from Maurice Wilkes relative to this issue. > Also, the assignment operator only allows you to copy from the same > type, but it's often the case that the source or target of the > assignment is some other kind of container (e.g. an array). Exactly. This is one reason for not providing assignment over a limited type. Instead, we typically create a copy procedure and declare the name of that copy procedure as specifically as possible. > > It is rare that one even needs to override the assignment operator > > on a non-limited type. There is a distinction here that will not > > be immediately obvious to the C++ programmer. > > You almost always need to override the assignment operator for a > non-limited type, if the type allocates internal storage from a pool. True when using indirection in your design. Also true for nearly any composite type (where the partial definition is private). Not true when the full definition is not composite. There is certainly overlap in the concerns of the Ada and C++ programmer. I think the Ada programmer has an easier time with this than the C++ programmer. Richard Riehle