Line data Source code
1 : #ifndef BOOST_CORE_CHECKED_DELETE_HPP 2 : #define BOOST_CORE_CHECKED_DELETE_HPP 3 : 4 : // MS compatible compilers support #pragma once 5 : 6 : #if defined(_MSC_VER) && (_MSC_VER >= 1020) 7 : # pragma once 8 : #endif 9 : 10 : #include <boost/config.hpp> 11 : 12 : // 13 : // boost/checked_delete.hpp 14 : // 15 : // Copyright (c) 2002, 2003 Peter Dimov 16 : // Copyright (c) 2003 Daniel Frey 17 : // Copyright (c) 2003 Howard Hinnant 18 : // 19 : // Distributed under the Boost Software License, Version 1.0. (See 20 : // accompanying file LICENSE_1_0.txt or copy at 21 : // http://www.boost.org/LICENSE_1_0.txt) 22 : // 23 : // See http://www.boost.org/libs/core/doc/html/core/checked_delete.html for documentation. 24 : // 25 : 26 : namespace boost 27 : { 28 : 29 : // verify that types are complete for increased safety 30 : 31 0 : template<class T> inline void checked_delete(T * x) BOOST_NOEXCEPT 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 0 : delete x; 37 0 : } 38 : 39 0 : template<class T> inline void checked_array_delete(T * x) BOOST_NOEXCEPT 40 : { 41 : typedef char type_must_be_complete[ sizeof(T)? 1: -1 ]; 42 : (void) sizeof(type_must_be_complete); 43 0 : 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 BOOST_NOEXCEPT 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 0 : void operator()(T * x) const BOOST_NOEXCEPT 64 : { 65 0 : boost::checked_array_delete(x); 66 : } 67 : }; 68 : 69 : } // namespace boost 70 : 71 : #endif // #ifndef BOOST_CORE_CHECKED_DELETE_HPP