Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/smart_ptr/compatibility.htm @ 20

Last change on this file since 20 was 12, checked in by landauf, 18 years ago

added boost

File size: 3.9 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2
3<html>
4
5<head>
6<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
7<title>Smart Pointer Changes</title>
8</head>
9
10<body bgcolor="#FFFFFF" text="#000000">
11
12<h1><img src="../../boost.png" alt="boost.png (6897 bytes)" align="middle" width="277" height="86">Smart
13Pointer Changes</h1>
14
15<p>The February 2002 change to the Boost smart pointers introduced a number
16of changes. Since the previous version of the smart pointers was in use for
17a long time, it's useful to have a detailed list of what changed from a library
18user's point of view.</p>
19
20<p>Note that for compilers that don't support member templates well enough,
21a separate implementation is used that lacks many of the new features and is
22more like the old version.</p>
23
24<h2>Features Requiring Code Changes to Take Advantage</h2>
25
26<ul>
27
28<li>The smart pointer class templates now each have their own header file.
29For compatibility, the
30<a href="../../boost/smart_ptr.hpp">&lt;boost/smart_ptr.hpp&gt;</a>
31header now includes the headers for the four classic smart pointer class templates.</li>
32
33<li>The <b>weak_ptr</b> template was added.</li>
34
35<li>The new <b>shared_ptr</b> and <b>shared_array</b> relax the requirement that the pointed-to object's
36destructor must be visible when instantiating the <b>shared_ptr</b> destructor.
37This makes it easier to have shared_ptr members in classes without explicit destructors.</li>
38
39<li>A custom deallocator can be passed in when creating a <b>shared_ptr</b> or <b>shared_array</b>.</li>
40
41<li><b>shared_static_cast</b> and <b>shared_dynamic_cast</b> function templates are
42provided which work for <b>shared_ptr</b> and <b>weak_ptr</b> as <b>static_cast</b> and
43<b>dynamic_cast</b> do for pointers.</li>
44
45<li>The self-assignment misfeature has been removed from <b>shared_ptr::reset</b>,
46although it is still present in <b>scoped_ptr</b>, and in <b>std::auto_ptr</b>.
47Calling <b>reset</b> with a pointer to the object that's already owned by the
48<b>shared_ptr</b> results in undefined behavior
49(an assertion, or eventually a double-delete if assertions are off).</li>
50
51<li>The <b>BOOST_SMART_PTR_CONVERSION</b> feature has been removed.</li>
52
53<li><b>shared_ptr&lt;void&gt;</b> is now allowed.</li>
54
55</ul>
56
57<h2>Features That Improve Robustness</h2>
58
59<ul>
60
61<li>The manipulation of use counts is now <a name="threadsafe">thread safe</a> on Windows, Linux, and platforms
62that support pthreads. See the
63<a href="../../boost/detail/atomic_count.hpp">&lt;boost/detail/atomic_count.hpp&gt;</a>
64file for details</li>
65
66<li>The new shared_ptr will always delete the object using the pointer it was originally constructed with.
67This prevents subtle problems that could happen if the last <b>shared_ptr</b> was a pointer to a sub-object
68of a class that did not have a virtual destructor.</li>
69
70</ul>
71
72<h2>Implementation Details</h2>
73
74<ul>
75
76<li>Some bugs in the assignment operator implementations and in <b>reset</b>
77have been fixed by using the &quot;copy and swap&quot; idiom.</li>
78
79<li>Assertions have been added to check preconditions of various functions;
80however, since these use the new
81<a href="../../boost/assert.hpp">&lt;boost/assert.hpp&gt;</a>
82header, the assertions are disabled by default.</li>
83
84<li>The partial specialization of <b>std::less</b> has been replaced by <b>operator&lt;</b>
85overloads which accomplish the same thing without relying on undefined behavior.</li>
86
87<li>The incorrect overload of <b>std::swap</b> has been replaced by <b>boost::swap</b>, which
88has many of the same advantages for generic programming but does not violate the C++ standard.</li>
89
90</ul>
91
92<hr>
93
94<p>Revised 1 February 2002</p>
95
96<p>Copyright 2002 Darin Adler.
97Permission to copy, use,
98modify, sell and distribute this document is granted provided this copyright
99notice appears in all copies. This document is provided &quot;as is&quot;
100without express or implied warranty, and with no claim as to its suitability for
101any purpose.</p>
102
103</body>
104
105</html>
Note: See TracBrowser for help on using the repository browser.