🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

auto_ptr and deep copy semantics

#2853
From: Avner Ben
Date: Mon, 04 Dec 1995 21:08
28 lines
2070 bytes
This message was somehow lost in the process of  transfer, so I submit it again:

I find it hard to understand the reason behind template class auto_ptr's (April draft) "strict ownership semantics." Its copy-constructor and assignment operator call __release__ on the source, and thus "effectiviely transfer control" of the pointed object. 
I am dissapointed. I expected auto_ptr or a simmilar variety to feature __deep-copy-semantics__. Of-course, this variiety is more restrictive - it requires the template paramter to have copy-constructor, assignment operator and destructor. The obvious use for deep_copy_auto_ptr is to simplify the maintainance of containers of pointers to objects. The STL makes life hard when you embed, in a class, a member that is a template instantiation of a container on pointer type. You must write you own ccotr, assignment operator and destructor for the enclosing class, to ensure the deep-copy semantics. You are excempt from it, when you embed a container that stores objects by value. Writing one's own deep_copy_auto_ptr template solves the problem. I am surprised to find that this simple facility is not part of the language! (Or I may be wrong in my whole endestanding of STL usage).

	Avner Ben | avnerben@netvision.net.il



[ 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: <01BAC29C.C79C35A0@ts3ap3.NetVision.net.il>
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage
From: Avner Ben <avnerben@netvision.net.il>
Newsgroups: comp.std.c++
Subject: auto_ptr and deep copy semantics
Date: 4 Dec 1995 21:08:55 GMT
Organization: ?
Approved: clamage@eng.sun.com (comp.std.c++)
Message-ID: <01BAC29C.C79C35A0@ts3ap3.NetVision.net.il>
NNTP-Posting-Host: taumet.eng.sun.com
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
X-Lines: 24
Content-Length: 1302
Originator: clamage@taumet