🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

auto_ptr and deep-copy semantics

#2674
From: Avner Ben
Date: Wed, 22 Nov 1995 03:24
23 lines
1968 bytes
I find it hard to understand the reason behind template class auto_ptr's (DWG 20.4.5) "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 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!

			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: <01BAB85F.3A589E00@ts33p12.NetVision.net.il>
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
Date: 22 Nov 95 03:24:43 GMT
Approved: fjh@cs.mu.oz.au
Organization: -
Newsgroups: comp.std.c++
Message-ID: <01BAB85F.3A589E00@ts33p12.NetVision.net.il>
From: Avner Ben <avnerben@netvision.net.il>
Subject: auto_ptr and deep-copy semantics
X-Original-Date: Tue, 21 Nov 1995 22:17:36 +-200
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMLKYKuEDnX0m9pzZAQElKAGAiXnMxdtt9fkx4dFuQgAe28h0CFbbxPPr
 dN/nE8+gohzTswskZIId4MJiug9ciGKu
 =mGY9