CppCMS
|
00001 #ifndef BOOSTER_CHECKED_DELETE_H 00002 #define BOOSTER_CHECKED_DELETE_H 00003 00004 // 00005 // boost/checked_delete.hpp 00006 // 00007 // Copyright (c) 2002, 2003 Peter Dimov 00008 // Copyright (c) 2003 Daniel Frey 00009 // Copyright (c) 2003 Howard Hinnant 00010 // 00011 // Distributed under the Boost Software License, Version 1.0. (See 00012 // accompanying file LICENSE_1_0.txt or copy at 00013 // http://www.boost.org/LICENSE_1_0.txt) 00014 // 00015 // See http://www.boost.org/libs/utility/checked_delete.html for documentation. 00016 // 00017 00018 namespace booster 00019 { 00020 00022 00023 // verify that types are complete for increased safety 00024 00025 template<class T> inline void checked_delete(T * x) 00026 { 00027 // intentionally complex - simplification causes regressions 00028 typedef char type_must_be_complete[ sizeof(T)? 1: -1 ]; 00029 (void) sizeof(type_must_be_complete); 00030 delete x; 00031 } 00032 00033 template<class T> inline void checked_array_delete(T * x) 00034 { 00035 typedef char type_must_be_complete[ sizeof(T)? 1: -1 ]; 00036 (void) sizeof(type_must_be_complete); 00037 delete [] x; 00038 } 00039 00040 template<class T> struct checked_deleter 00041 { 00042 typedef void result_type; 00043 typedef T * argument_type; 00044 00045 void operator()(T * x) const 00046 { 00047 // boost:: disables ADL 00048 booster::checked_delete(x); 00049 } 00050 }; 00051 00052 template<class T> struct checked_array_deleter 00053 { 00054 typedef void result_type; 00055 typedef T * argument_type; 00056 00057 void operator()(T * x) const 00058 { 00059 booster::checked_array_delete(x); 00060 } 00061 }; 00063 } // namespace boost 00064 00065 #endif // #ifndef BOOST_CHECKED_DELETE_HPP_INCLUDED