2 / Copyright (c) 2002, 2003, 2005 Peter Dimov
3 / Copyright (c) 2014 Glen Fernandes
5 / Distributed under the Boost Software License, Version 1.0. (See
6 / accompanying file LICENSE_1_0.txt or copy at
7 / http://www.boost.org/LICENSE_1_0.txt)
10 [section:checked_delete checked_delete]
24 The header `<boost/checked_delete.hpp>` defines two function
25 templates, `checked_delete` and `checked_array_delete`, and two
26 class templates, `checked_deleter` and `checked_array_deleter`.
28 The C++ Standard allows, in 5.3.5/5, pointers to incomplete
29 class types to be deleted with a delete-expression. When the
30 class has a non-trivial destructor, or a class-specific
31 operator delete, the behavior is undefined. Some compilers
32 issue a warning when an incomplete type is deleted, but
33 unfortunately, not all do, and programmers sometimes ignore or
36 A particularly troublesome case is when a smart pointer's
37 destructor, such as `boost::scoped_ptr<T>::~scoped_ptr`, is
38 instantiated with an incomplete type. This can often lead to
39 silent, hard to track failures.
41 The supplied function and class templates can be used to
42 prevent these problems, as they require a complete type, and
43 cause a compilation error otherwise.
52 template<class T> void checked_delete(T * p);
53 template<class T> void checked_array_delete(T * p);
54 template<class T> struct checked_deleter;
55 template<class T> struct checked_array_deleter;
61 [section checked_delete]
63 [section template<class T> void checked_delete(T * p);]
65 * *Requires:* `T` must be a complete type. The expression
66 `delete p` must be well-formed.
67 * *Effects:* `delete p;`
73 [section checked_array_delete]
75 [section template<class T> void checked_array_delete(T * p);]
77 * *Requires:* `T` must be a complete type. The expression
78 `delete [] p` must be well-formed.
79 * *Effects:* `delete [] p;`
85 [section checked_deleter]
88 template<class T> struct checked_deleter
90 typedef void result_type;
91 typedef T * argument_type;
92 void operator()(T * p) const;
96 [section void checked_deleter<T>::operator()(T * p) const;]
98 * *Requires:* `T` must be a complete type. The expression
99 `delete p` must be well-formed.
100 * *Effects:* `delete p;`
106 [section checked_array_deleter]
109 template<class T> struct checked_array_deleter
111 typedef void result_type;
112 typedef T * argument_type;
113 void operator()(T * p) const;
117 [section void checked_array_deleter<T>::operator()(T * p) const;]
119 * *Requires:* `T` must be a complete type. The expression
120 `delete [] p` must be well-formed.
121 * *Effects:* `delete [] p;`
127 [section Acknowledgements]
129 The function templates `checked_delete` and
130 `checked_array_delete` were originally part of
131 `<boost/utility.hpp>`, and the documentation
132 acknowledged Beman Dawes, Dave Abrahams,
133 Vladimir Prus, Rainer Deyke, John Maddock,
134 and others as contributors.