annotate DEPENDENCIES/generic/include/boost/checked_delete.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
rev   line source
Chris@16 1 #ifndef BOOST_CHECKED_DELETE_HPP_INCLUDED
Chris@16 2 #define BOOST_CHECKED_DELETE_HPP_INCLUDED
Chris@16 3
Chris@16 4 // MS compatible compilers support #pragma once
Chris@16 5
Chris@16 6 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
Chris@16 7 # pragma once
Chris@16 8 #endif
Chris@16 9
Chris@16 10 //
Chris@16 11 // boost/checked_delete.hpp
Chris@16 12 //
Chris@16 13 // Copyright (c) 2002, 2003 Peter Dimov
Chris@16 14 // Copyright (c) 2003 Daniel Frey
Chris@16 15 // Copyright (c) 2003 Howard Hinnant
Chris@16 16 //
Chris@16 17 // Distributed under the Boost Software License, Version 1.0. (See
Chris@16 18 // accompanying file LICENSE_1_0.txt or copy at
Chris@16 19 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 20 //
Chris@16 21 // See http://www.boost.org/libs/utility/checked_delete.html for documentation.
Chris@16 22 //
Chris@16 23
Chris@16 24 namespace boost
Chris@16 25 {
Chris@16 26
Chris@16 27 // verify that types are complete for increased safety
Chris@16 28
Chris@16 29 template<class T> inline void checked_delete(T * x)
Chris@16 30 {
Chris@16 31 // intentionally complex - simplification causes regressions
Chris@16 32 typedef char type_must_be_complete[ sizeof(T)? 1: -1 ];
Chris@16 33 (void) sizeof(type_must_be_complete);
Chris@16 34 delete x;
Chris@16 35 }
Chris@16 36
Chris@16 37 template<class T> inline void checked_array_delete(T * x)
Chris@16 38 {
Chris@16 39 typedef char type_must_be_complete[ sizeof(T)? 1: -1 ];
Chris@16 40 (void) sizeof(type_must_be_complete);
Chris@16 41 delete [] x;
Chris@16 42 }
Chris@16 43
Chris@16 44 template<class T> struct checked_deleter
Chris@16 45 {
Chris@16 46 typedef void result_type;
Chris@16 47 typedef T * argument_type;
Chris@16 48
Chris@16 49 void operator()(T * x) const
Chris@16 50 {
Chris@16 51 // boost:: disables ADL
Chris@16 52 boost::checked_delete(x);
Chris@16 53 }
Chris@16 54 };
Chris@16 55
Chris@16 56 template<class T> struct checked_array_deleter
Chris@16 57 {
Chris@16 58 typedef void result_type;
Chris@16 59 typedef T * argument_type;
Chris@16 60
Chris@16 61 void operator()(T * x) const
Chris@16 62 {
Chris@16 63 boost::checked_array_delete(x);
Chris@16 64 }
Chris@16 65 };
Chris@16 66
Chris@16 67 } // namespace boost
Chris@16 68
Chris@16 69 #endif // #ifndef BOOST_CHECKED_DELETE_HPP_INCLUDED