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 217326 : template<class T> inline void checked_delete(T * x) BOOST_NOEXCEPT 32 : { 33 : #if defined(__cpp_static_assert) && __cpp_static_assert >= 200410L 34 : 35 : static_assert( sizeof(T) != 0, "Type must be complete" ); 36 : 37 : #else 38 : 39 : typedef char type_must_be_complete[ sizeof(T) ]; 40 : (void) sizeof(type_must_be_complete); 41 : 42 : #endif 43 : 44 217326 : delete x; 45 217326 : } 46 : 47 292 : template<class T> inline void checked_array_delete(T * x) BOOST_NOEXCEPT 48 : { 49 : #if defined(__cpp_static_assert) && __cpp_static_assert >= 200410L 50 : 51 : static_assert( sizeof(T) != 0, "Type must be complete" ); 52 : 53 : #else 54 : 55 : typedef char type_must_be_complete[ sizeof(T) ]; 56 : (void) sizeof(type_must_be_complete); 57 : 58 : #endif 59 : 60 292 : delete [] x; 61 292 : } 62 : 63 : // Block unintended ADL 64 : namespace checked_deleters 65 : { 66 : 67 : template<class T> struct checked_deleter 68 : { 69 : typedef void result_type; 70 : typedef T * argument_type; 71 : 72 : void operator()(T * x) const BOOST_NOEXCEPT 73 : { 74 : // boost:: disables ADL 75 : boost::checked_delete(x); 76 : } 77 : }; 78 : 79 : template<class T> struct checked_array_deleter 80 : { 81 : typedef void result_type; 82 : typedef T * argument_type; 83 : 84 : void operator()(T * x) const BOOST_NOEXCEPT 85 : { 86 : boost::checked_array_delete(x); 87 : } 88 : }; 89 : 90 : } // namespace checked_deleters 91 : 92 : using checked_deleters::checked_deleter; 93 : using checked_deleters::checked_array_deleter; 94 : 95 : } // namespace boost 96 : 97 : #endif // #ifndef BOOST_CORE_CHECKED_DELETE_HPP