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,f51e93dacd9c7fca X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-06-18 08:45:05 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!uunet!sea.uu.net!sac.uu.net!dfw.uu.net!ash.uu.net!spool0902.news.uu.net!not-for-mail Message-ID: <3D0F558D.9030403@mail.com> Date: Tue, 18 Jun 2002 11:45:17 -0400 From: Hyman Rosen User-Agent: Mozilla/5.0 (Windows; U; WinNT4.0; en-US; rv:1.0.0) Gecko/20020530 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: status of Ada STL? References: <3d0ce154_5@news.bluewin.ch> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Organization: KBC Financial Products Cache-Post-Path: master.nyc.kbcfp.com!unknown@mosquito.nyc.kbcfp.com X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/) NNTP-Posting-Host: 204.253.250.10 X-Trace: 1024415070 8950 204.253.250.10 Xref: archiver1.google.com comp.lang.ada:26252 Date: 2002-06-18T11:45:17-04:00 List-Id: Fraser Wilson wrote: > C++ seems to tie itself in knots over the issue of temporaries, which > is why constructs such as the above have to be used. The arithmetic assignment operators all existed in C, some decades before C++ ever existed. The usual argument is that when you are operating on a long name, you don't want to say it more than once - myArray[10].subfield1.subarray[5].z /= 2; More likely, it helps with stepping through an array with a post-incrementing pointer, where you simply cannot repeat the name of the object - while (begin != end) *begin++ /= 2; As far as temporaries go, it's simply a fact that operating in place on an object is likely to be more efficient than making a new one and copying it about. For reasonably complex objects, it is hopeless to think that the compiler can raeson this out for you. The usual C++ technique is to write the infix operators in terms of the assignment ones - struct X { X &operator/=(const X &other) { /* do something */ return *this; } X operator/(const X &other) { X x = *this; return x /= other; } };