vbl_checked_delete.h
Go to the documentation of this file.
1 #ifndef vbl_checked_delete_h_
2 #define vbl_checked_delete_h_
3 //:
4 // \file
5 // \author Amitha Perera
6 // Checked delete function lifted from BOOST.
7 //
8 // boost/checked_delete.hpp
9 //
10 // Copyright (c) 1999, 2000, 2001, 2002 boost.org
11 // Copyright (c) 2002, 2003 Peter Dimov
12 // Copyright (c) 2003 Daniel Frey
13 // Copyright (c) 2003 Howard Hinnant
14 //
15 // Permission to copy, use, modify, sell and distribute this software
16 // is granted provided this copyright notice appears in all copies.
17 // This software is provided "as is" without express or implied
18 // warranty, and with no claim as to its suitability for any purpose.
19 //
20 // See http://www.boost.org/libs/utility/checked_delete.html for documentation.
21 //
22 // Modified from the original boost sources to fit the VXL restrictions.
23 
24 //: Checks that T is complete and deletes x.
25 // Not to be used on arrays!
26 template<class T>
27 inline
28 void vbl_checked_delete(T * x)
29 {
30  // intentionally complex - simplification causes regressions
31  typedef char type_must_be_complete[ sizeof(T)? 1: -1 ];
32  (void) sizeof(type_must_be_complete);
33  delete x;
34 }
35 
36 //: Checks that T is complete and array deletes x.
37 template<class T>
38 inline
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 #endif // vbl_checked_delete_h_
void vbl_checked_delete_array(T *x)
Checks that T is complete and array deletes x.
void vbl_checked_delete(T *x)
Checks that T is complete and deletes x.