🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2334

Re: Q: is A a = 100; equivalent to A a (10

#2334
From: Steve Clamage
Date: Sat, 28 Oct 1995 07:44
33 lines
1774 bytes
In article 814802135@cadlab, martelli@cadlab.cadlab.it (Alex Martelli) writes:
>clamage@Eng.Sun.COM (Steve Clamage) writes:
>	...
>>It is sometimes also necessary to point out the difference between copy
>>construction and copy assignment.
>>	// T is a type, and x is not type T
>>	T t1 = x; // may omit a temp T and avoid copying it
>>	T t2;
>>	t2 = x; // must create a temp T and assign it to t2
>
>This only applies if class T does not define an "operator=(X const&)"
>(or, similar ones taking an X or an X&), where x's type is X, right?

Right. I was trying to make the point that copy construction can
sometimes be omitted, but copy assignment cannot be optimized away.
(Modulo the "as-if" rule. If you can't detect a difference, there
isn't a difference.)

Once again, I only point this out to emphasize that you should design
classes so that the correctness of the program does not depend on whether
extra temporaries are created and copied. The language definition allows
implementors considerable leeway in creating or avoiding temps. 
---
Steve Clamage, stephen.clamage@eng.sun.com




---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <46rc47$558@engnews1.eng.sun.com>
Path: arc1-ca.pugleaf.net!news.mindlink.net!agate!agate!Matt
References: <martelli.814802135@cadlab>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.mindlink.net!agate!agate!Matt
From: clamage@Eng.Sun.COM (Steve Clamage)
Newsgroups: comp.std.c++
Subject: Re: Q: is A a = 100; equivalent to A a (10
Date: 28 Oct 1995 07:44:36 GMT
Organization: Sun Microsystems Inc.
Approved: Matt@Austern
Message-ID: <46rc47$558@engnews1.eng.sun.com>
References: <martelli.814802135@cadlab>
Reply-To: clamage@Eng.Sun.COM
NNTP-Posting-Host: austern.hip.berkeley.edu