Topic: auto_ptr and deep-copy semantics
Author: Avner Ben <avnerben@netvision.net.il>
Date: 1995/11/22 Raw View
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.=20
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. ]