Chris@102
|
1 #ifndef BOOST_CORE_CHECKED_DELETE_HPP
|
Chris@102
|
2 #define BOOST_CORE_CHECKED_DELETE_HPP
|
Chris@102
|
3
|
Chris@102
|
4 // MS compatible compilers support #pragma once
|
Chris@102
|
5
|
Chris@102
|
6 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
Chris@102
|
7 # pragma once
|
Chris@102
|
8 #endif
|
Chris@102
|
9
|
Chris@102
|
10 //
|
Chris@102
|
11 // boost/checked_delete.hpp
|
Chris@102
|
12 //
|
Chris@102
|
13 // Copyright (c) 2002, 2003 Peter Dimov
|
Chris@102
|
14 // Copyright (c) 2003 Daniel Frey
|
Chris@102
|
15 // Copyright (c) 2003 Howard Hinnant
|
Chris@102
|
16 //
|
Chris@102
|
17 // Distributed under the Boost Software License, Version 1.0. (See
|
Chris@102
|
18 // accompanying file LICENSE_1_0.txt or copy at
|
Chris@102
|
19 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@102
|
20 //
|
Chris@102
|
21 // See http://www.boost.org/libs/core/doc/html/core/checked_delete.html for documentation.
|
Chris@102
|
22 //
|
Chris@102
|
23
|
Chris@102
|
24 namespace boost
|
Chris@102
|
25 {
|
Chris@102
|
26
|
Chris@102
|
27 // verify that types are complete for increased safety
|
Chris@102
|
28
|
Chris@102
|
29 template<class T> inline void checked_delete(T * x)
|
Chris@102
|
30 {
|
Chris@102
|
31 // intentionally complex - simplification causes regressions
|
Chris@102
|
32 typedef char type_must_be_complete[ sizeof(T)? 1: -1 ];
|
Chris@102
|
33 (void) sizeof(type_must_be_complete);
|
Chris@102
|
34 delete x;
|
Chris@102
|
35 }
|
Chris@102
|
36
|
Chris@102
|
37 template<class T> inline void checked_array_delete(T * x)
|
Chris@102
|
38 {
|
Chris@102
|
39 typedef char type_must_be_complete[ sizeof(T)? 1: -1 ];
|
Chris@102
|
40 (void) sizeof(type_must_be_complete);
|
Chris@102
|
41 delete [] x;
|
Chris@102
|
42 }
|
Chris@102
|
43
|
Chris@102
|
44 template<class T> struct checked_deleter
|
Chris@102
|
45 {
|
Chris@102
|
46 typedef void result_type;
|
Chris@102
|
47 typedef T * argument_type;
|
Chris@102
|
48
|
Chris@102
|
49 void operator()(T * x) const
|
Chris@102
|
50 {
|
Chris@102
|
51 // boost:: disables ADL
|
Chris@102
|
52 boost::checked_delete(x);
|
Chris@102
|
53 }
|
Chris@102
|
54 };
|
Chris@102
|
55
|
Chris@102
|
56 template<class T> struct checked_array_deleter
|
Chris@102
|
57 {
|
Chris@102
|
58 typedef void result_type;
|
Chris@102
|
59 typedef T * argument_type;
|
Chris@102
|
60
|
Chris@102
|
61 void operator()(T * x) const
|
Chris@102
|
62 {
|
Chris@102
|
63 boost::checked_array_delete(x);
|
Chris@102
|
64 }
|
Chris@102
|
65 };
|
Chris@102
|
66
|
Chris@102
|
67 } // namespace boost
|
Chris@102
|
68
|
Chris@102
|
69 #endif // #ifndef BOOST_CORE_CHECKED_DELETE_HPP
|