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