File: checked_delete.html

package info (click to toggle)
boost 1.33.1-10
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 100,948 kB
  • ctags: 145,103
  • sloc: cpp: 573,492; xml: 49,055; python: 15,626; ansic: 13,588; sh: 2,099; yacc: 858; makefile: 660; perl: 427; lex: 111; csh: 6
file content (124 lines) | stat: -rw-r--r-- 4,406 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
	<head>
		<title>Boost: checked_delete.hpp documentation</title>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
	</head>
	<body bgcolor="white" style="MARGIN-LEFT: 5%; MARGIN-RIGHT: 5%">
		<table border="0" width="100%">
			<tr>
				<td width="277">
					<img src="../../boost.png" alt="boost.png (6897 bytes)" width="277" height="86">
				</td>
				<td align="middle">
					<h1>checked_delete.hpp</h1>
				</td>
			</tr>
			<tr>
				<td colspan="2" height="64">&nbsp;</td>
			</tr>
		</table>
		<p>
			The header <STRONG>&lt;boost/checked_delete.hpp&gt;</STRONG> defines two 
			function templates, <STRONG>checked_delete</STRONG> and <STRONG>checked_array_delete</STRONG>, 
			and two class templates, <STRONG>checked_deleter</STRONG> and <STRONG>checked_array_deleter</STRONG>.
		</p>
		<P>The C++ Standard allows, in 5.3.5/5, pointers to incomplete class types to be 
			deleted with a <EM>delete-expression</EM>. When the class has a non-trivial 
			destructor, or a class-specific operator delete, the behavior is undefined. 
			Some compilers issue a warning when an incomplete type is deleted, but 
			unfortunately, not all do, and programmers sometimes ignore or disable 
			warnings.</P>
		<P>A particularly troublesome case is when a smart pointer's destructor, such as <STRONG>
				boost::scoped_ptr&lt;T&gt;::~scoped_ptr</STRONG>, is instantiated with an 
			incomplete type. This can often lead to silent, hard to track failures.</P>
		<P>The supplied function and class templates can be used to prevent these problems, 
			as they require a complete type, and cause a compilation error otherwise.</P>
		<h3><a name="Synopsis">Synopsis</a></h3>
		<pre>
namespace boost
{

template&lt;class T&gt; void checked_delete(T * p);
template&lt;class T&gt; void checked_array_delete(T * p);
template&lt;class T&gt; struct checked_deleter;
template&lt;class T&gt; struct checked_array_deleter;

}
</pre>
		<h3>checked_delete</h3>
		<h4><a name="checked_delete">template&lt;class T&gt; void checked_delete(T * p);</a></h4>
		<blockquote>
			<p>
				<b>Requires:</b> <b>T</b> must be a complete type. The expression <tt>delete p</tt>
				must be well-formed.
			</p>
			<p>
				<b>Effects:</b> <tt>delete p;</tt>
			</p>
		</blockquote>
		<h3>checked_array_delete</h3>
		<h4><a name="checked_array_delete">template&lt;class T&gt; void checked_array_delete(T 
				* p);</a></h4>
		<blockquote>
			<p>
				<b>Requires:</b> <b>T</b> must be a complete type. The expression <tt>delete [] p</tt>
				must be well-formed.
			</p>
			<p>
				<b>Effects:</b> <tt>delete [] p;</tt>
			</p>
		</blockquote>
		<h3>checked_deleter</h3>
		<pre>
template&lt;class T&gt; struct checked_deleter
{
    typedef void result_type;
    typedef T * argument_type;
    void operator()(T * p) const;
};
</pre>
		<h4>void checked_deleter&lt;T&gt;::operator()(T * p) const;</h4>
		<blockquote>
			<p>
				<b>Requires:</b> <b>T</b> must be a complete type. The expression <tt>delete p</tt>
				must be well-formed.
			</p>
			<p>
				<b>Effects:</b> <tt>delete p;</tt>
			</p>
		</blockquote>
		<h3>checked_array_deleter</h3>
		<pre>
template&lt;class T&gt; struct checked_array_deleter
{
    typedef void result_type;
    typedef T * argument_type;
    void operator()(T * p) const;
};
</pre>
		<h4>void checked_array_deleter&lt;T&gt;::operator()(T * p) const;</h4>
		<blockquote>
			<p>
				<b>Requires:</b> <b>T</b> must be a complete type. The expression <tt>delete [] p</tt>
				must be well-formed.
			</p>
			<p>
				<b>Effects:</b> <tt>delete [] p;</tt>
			</p>
		</blockquote>
		<h3><a name="Acknowledgements">Acknowledgements</a></h3>
		<p>
			The function templates <STRONG>checked_delete</STRONG> and <STRONG>checked_array_delete</STRONG>
			were originally part of <STRONG>&lt;boost/utility.hpp&gt;</STRONG>, and the 
			documentation acknowledged Beman Dawes, Dave Abrahams, Vladimir Prus, Rainer 
			Deyke, John Maddock, and others as contributors.
		</p>
		<p>
			<br>
			<small>Copyright  2002 by Peter Dimov. Permission to copy, use, modify, sell and 
				distribute this document is granted provided this copyright notice appears in 
				all copies. This document is provided "as is" without express or implied 
				warranty, and with no claim as to its suitability for any purpose.</small></p>
	</body>
</html>