forked from boostorg/core
Merge branch 'master' into develop
This commit is contained in:
@@ -1,122 +0,0 @@
|
|||||||
<!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"><A href="../../index.htm"> <img src="../../boost.png" alt="boost.png (6897 bytes)" width="277" height="86" border="0"></A>
|
|
||||||
</td>
|
|
||||||
<td align="center">
|
|
||||||
<h1>checked_delete.hpp</h1>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td colspan="2" height="64"> </td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
<p>
|
|
||||||
The header <STRONG><boost/checked_delete.hpp></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<T>::~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<class T> void checked_delete(T * p);
|
|
||||||
template<class T> void checked_array_delete(T * p);
|
|
||||||
template<class T> struct checked_deleter;
|
|
||||||
template<class T> struct checked_array_deleter;
|
|
||||||
|
|
||||||
}
|
|
||||||
</pre>
|
|
||||||
<h3>checked_delete</h3>
|
|
||||||
<h4><a name="checked_delete">template<class T> 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<class T> 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<class T> struct checked_deleter
|
|
||||||
{
|
|
||||||
typedef void result_type;
|
|
||||||
typedef T * argument_type;
|
|
||||||
void operator()(T * p) const;
|
|
||||||
};
|
|
||||||
</pre>
|
|
||||||
<h4>void checked_deleter<T>::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<class T> struct checked_array_deleter
|
|
||||||
{
|
|
||||||
typedef void result_type;
|
|
||||||
typedef T * argument_type;
|
|
||||||
void operator()(T * p) const;
|
|
||||||
};
|
|
||||||
</pre>
|
|
||||||
<h4>void checked_array_deleter<T>::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><boost/utility.hpp></STRONG>, and the
|
|
||||||
documentation acknowledged Beman Dawes, Dave Abrahams, Vladimir Prus, Rainer
|
|
||||||
Deyke, John Maddock, and others as contributors.
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
<br>
|
|
||||||
<small>Copyright <20> 2002 by Peter Dimov. Distributed under the Boost Software License, Version
|
|
||||||
1.0. See accompanying file <A href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</A> or
|
|
||||||
copy at <A href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</A>.</small></p>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
114
doc/checked_delete.qbk
Normal file
114
doc/checked_delete.qbk
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
[section:checked_delete Header <boost/core/checked_delete.hpp>]
|
||||||
|
|
||||||
|
The header *<boost/checked_delete.hpp>* defines two function
|
||||||
|
templates, *checked_delete* and *checked_array_delete*, and two
|
||||||
|
class templates, *checked_deleter* and *checked_array_deleter*.
|
||||||
|
|
||||||
|
The C++ Standard allows, in 5.3.5/5, pointers to incomplete
|
||||||
|
class types to be deleted with a delete-expression. 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.
|
||||||
|
|
||||||
|
A particularly troublesome case is when a smart pointer's
|
||||||
|
destructor, such as *boost::scoped_ptr<T>::~scoped_ptr*, is
|
||||||
|
instantiated with an incomplete type. This can often lead to
|
||||||
|
silent, hard to track failures.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
[section Synopsis]
|
||||||
|
|
||||||
|
``
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
template<class T> void checked_delete(T * p);
|
||||||
|
template<class T> void checked_array_delete(T * p);
|
||||||
|
template<class T> struct checked_deleter;
|
||||||
|
template<class T> struct checked_array_deleter;
|
||||||
|
}
|
||||||
|
``
|
||||||
|
|
||||||
|
[endsect]
|
||||||
|
|
||||||
|
[section checked_delete]
|
||||||
|
|
||||||
|
[section `template<class T> void checked_delete(T * p);`]
|
||||||
|
|
||||||
|
* *Requires:* *T* must be a complete type. The expression
|
||||||
|
`delete p` must be well-formed.
|
||||||
|
* *Effects:* `delete p;`
|
||||||
|
|
||||||
|
[endsect]
|
||||||
|
|
||||||
|
[endsect]
|
||||||
|
|
||||||
|
[section checked_array_delete]
|
||||||
|
|
||||||
|
[section `template<class T> void checked_array_delete(T * p);`]
|
||||||
|
|
||||||
|
* *Requires:* *T* must be a complete type. The expression
|
||||||
|
`delete [] p` must be well-formed.
|
||||||
|
* *Effects:* `delete [] p;`
|
||||||
|
|
||||||
|
[endsect]
|
||||||
|
|
||||||
|
[endsect]
|
||||||
|
|
||||||
|
[section checked_deleter]
|
||||||
|
|
||||||
|
``
|
||||||
|
template<class T> struct checked_deleter
|
||||||
|
{
|
||||||
|
typedef void result_type;
|
||||||
|
typedef T * argument_type;
|
||||||
|
void operator()(T * p) const;
|
||||||
|
};
|
||||||
|
``
|
||||||
|
|
||||||
|
[section `void checked_deleter<T>::operator()(T * p) const;`]
|
||||||
|
|
||||||
|
* *Requires:* `T` must be a complete type. The expression
|
||||||
|
`delete p` must be well-formed.
|
||||||
|
* *Effects:* `delete p;`
|
||||||
|
|
||||||
|
[endsect]
|
||||||
|
|
||||||
|
[endsect]
|
||||||
|
|
||||||
|
[section checked_array_deleter]
|
||||||
|
|
||||||
|
``
|
||||||
|
template<class T> struct checked_array_deleter
|
||||||
|
{
|
||||||
|
typedef void result_type;
|
||||||
|
typedef T * argument_type;
|
||||||
|
void operator()(T * p) const;
|
||||||
|
};
|
||||||
|
``
|
||||||
|
|
||||||
|
[section `void checked_array_deleter<T>::operator()(T * p) const;`]
|
||||||
|
* *Requires:* `T` must be a complete type. The expression
|
||||||
|
`delete [] p` must be well-formed.
|
||||||
|
* `Effects:` `delete [] p;`
|
||||||
|
|
||||||
|
[endsect]
|
||||||
|
|
||||||
|
[endsect]
|
||||||
|
|
||||||
|
[section Acknowledgements]
|
||||||
|
|
||||||
|
The function templates *checked_delete* and
|
||||||
|
*checked_array_delete* were originally part of
|
||||||
|
*<boost/utility.hpp>*, and the documentation
|
||||||
|
acknowledged Beman Dawes, Dave Abrahams,
|
||||||
|
Vladimir Prus, Rainer Deyke, John Maddock,
|
||||||
|
and others as contributors.
|
||||||
|
|
||||||
|
[endsect]
|
||||||
|
|
||||||
|
[endsect]
|
@@ -30,7 +30,7 @@ Currently, the Core library contains:
|
|||||||
[`boost::addressof`]
|
[`boost::addressof`]
|
||||||
]
|
]
|
||||||
[
|
[
|
||||||
[[@../../checked_delete.html checked_delete]]
|
[[link core.checked_delete checked_delete]]
|
||||||
[`boost::checked_delete`]
|
[`boost::checked_delete`]
|
||||||
]
|
]
|
||||||
[
|
[
|
||||||
@@ -73,6 +73,7 @@ Currently, the Core library contains:
|
|||||||
[endsect]
|
[endsect]
|
||||||
|
|
||||||
[include:core addressof.qbk]
|
[include:core addressof.qbk]
|
||||||
|
[include:core checked_delete.qbk]
|
||||||
[include:core explicit_operator_bool.qbk]
|
[include:core explicit_operator_bool.qbk]
|
||||||
[include:core lightweight_test.qbk]
|
[include:core lightweight_test.qbk]
|
||||||
[include:core no_exceptions_support.qbk]
|
[include:core no_exceptions_support.qbk]
|
||||||
|
Reference in New Issue
Block a user