🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Avner Ben Wed, 22 Nov 1995 03:24
auto_ptr and deep-copy semantics
#2674
Author: 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. ]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads