Debian Codegraph @

Source/boost/checked_delete.hpp

raw
1 #ifndef BOOST_CHECKED_DELETE_HPP_INCLUDED
2 #define BOOST_CHECKED_DELETE_HPP_INCLUDED
3
4 // MS compatible compilers support #pragma once
5
6 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
7 # pragma once
8 #endif
9
10 //
11 // boost/checked_delete.hpp
12 //
13 // Copyright (c) 1999, 2000, 2001, 2002 boost.org
14 // Copyright (c) 2002, 2003 Peter Dimov
15 // Copyright (c) 2003 Daniel Frey
16 // Copyright (c) 2003 Howard Hinnant
17 //
18 // Permission to copy, use, modify, sell and distribute this software
19 // is granted provided this copyright notice appears in all copies.
20 // This software is provided "as is" without express or implied
21 // warranty, and with no claim as to its suitability for any purpose.
22 //
23 // See http://www.boost.org/libs/utility/checked_delete.html for documentation.
24 //
25
26 namespace boost
27 {
28
29 // verify that types are complete for increased safety
30
31 template<class T> inline void checked_delete(T * x)
32 {
33 // intentionally complex - simplification causes regressions
34 typedef char type_must_be_complete[ sizeof(T)? 1: -1 ];
35 (void) sizeof(type_must_be_complete);
36 delete x;
37 }
38
39 template<class T> inline void checked_array_delete(T * x)
40 {
41 typedef char type_must_be_complete[ sizeof(T)? 1: -1 ];
42 (void) sizeof(type_must_be_complete);
43 delete [] x;
44 }
45
46 template<class T> struct checked_deleter
47 {
48 typedef void result_type;
49 typedef T * argument_type;
50
51 void operator()(T * x) const
52 {
53 // boost:: disables ADL
54 boost::checked_delete(x);
55 }
56 };
57
58 template<class T> struct checked_array_deleter
59 {
60 typedef void result_type;
61 typedef T * argument_type;
62
63 void operator()(T * x) const
64 {
65 boost::checked_array_delete(x);
66 }
67 };
68
69 } // namespace boost
70
71 #endif // #ifndef BOOST_CHECKED_DELETE_HPP_INCLUDED