core/vbl/vbl_checked_delete.h
Go to the documentation of this file.
00001 #ifndef vbl_checked_delete_h_
00002 #define vbl_checked_delete_h_
00003 //:
00004 // \file
00005 // \author Amitha Perera
00006 // Checked delete function lifted from BOOST.
00007 //
00008 //  boost/checked_delete.hpp
00009 //
00010 //  Copyright (c) 1999, 2000, 2001, 2002 boost.org
00011 //  Copyright (c) 2002, 2003 Peter Dimov
00012 //  Copyright (c) 2003 Daniel Frey
00013 //  Copyright (c) 2003 Howard Hinnant
00014 //
00015 //  Permission to copy, use, modify, sell and distribute this software
00016 //  is granted provided this copyright notice appears in all copies.
00017 //  This software is provided "as is" without express or implied
00018 //  warranty, and with no claim as to its suitability for any purpose.
00019 //
00020 //  See http://www.boost.org/libs/utility/checked_delete.html for documentation.
00021 //
00022 //  Modified from the original boost sources to fit the VXL restrictions.
00023 
00024 //: Checks that T is complete and deletes x.
00025 // Not to be used on arrays!
00026 template<class T>
00027 inline
00028 void vbl_checked_delete(T * x)
00029 {
00030     // intentionally complex - simplification causes regressions
00031     typedef char type_must_be_complete[ sizeof(T)? 1: -1 ];
00032     (void) sizeof(type_must_be_complete);
00033     delete x;
00034 }
00035 
00036 //: Checks that T is complete and array deletes x.
00037 template<class T>
00038 inline
00039 void vbl_checked_delete_array(T * x)
00040 {
00041     typedef char type_must_be_complete[ sizeof(T)? 1: -1 ];
00042     (void) sizeof(type_must_be_complete);
00043     delete [] x;
00044 }
00045 
00046 #endif  // vbl_checked_delete_h_