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,FREEMAIL_FROM autolearn=ham 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-02 11:56:59 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newshosting.com!news-xfer2.atl.newshosting.com!uunet!dca.uu.net!ash.uu.net!spool.news.uu.net!not-for-mail Date: Wed, 02 Jul 2003 14:27:13 -0400 From: Hyman Rosen User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.5a) Gecko/20030611 Thunderbird/0.1a X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: proposal for new assignment operators References: <9mEMa.86824$R73.10549@sccrnsc04> In-Reply-To: <9mEMa.86824$R73.10549@sccrnsc04> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Organization: KBC Financial Products Message-ID: <1057170433.957630@master.nyc.kbcfp.com> Cache-Post-Path: master.nyc.kbcfp.com!unknown@nightcrawler.nyc.kbcfp.com X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/) NNTP-Posting-Host: 204.253.250.10 X-Trace: 1057170434 14623 204.253.250.10 Xref: archiver1.google.com comp.lang.ada:39988 Date: 2003-07-02T14:27:13-04:00 List-Id: tmoran@acm.org wrote: > On a recent thread we were told that the usual idiom in C++ was > to do assignment a certain way to accomplish Finalization. "idiom" > suggests it's up to the programmer to do it right. When some complex > cases were mentioned, we were told basically that the programmer > would override assignment differently. Personally, I prefer having > the computer do it, and do it right, rather than having to do it > myself, possibly making a mistaake in the process. You probably misunderstood what you read, then. Ada's Controlled types don't offer anything extra over C++'s abilities. Writing your own assignment operator in C++ is similar to writing Adjust in Ada. The constructor is similar to Initialize, and the destructor is similar to Finalize. There are differences. In Ada, when a Controlled object is initialized with an aggregate, Initialize is not called. In C++, some constructor is always called. In Ada, assignment is done by Finalizing the target, doing a bitwise copy of a temporary object initialized from the source (although the temporary mayy be elided), then calling Adjust on the target. In C++, assignment is done by invoking the assignment operator. The default assignment operator does elementwise assignment for each subcomponent, but a user-written one may do whatever it deems appropriate.