2002-05-21 23:39:58 +00:00
|
|
|
#ifndef BOOST_CHECKED_DELETE_HPP_INCLUDED
|
|
|
|
#define BOOST_CHECKED_DELETE_HPP_INCLUDED
|
|
|
|
|
2004-02-05 09:14:22 +00:00
|
|
|
// MS compatible compilers support #pragma once
|
|
|
|
|
2003-08-07 12:09:24 +00:00
|
|
|
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
|
|
|
# pragma once
|
2002-05-21 23:39:58 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
//
|
|
|
|
// boost/checked_delete.hpp
|
|
|
|
//
|
2003-03-03 15:53:48 +00:00
|
|
|
// Copyright (c) 2002, 2003 Peter Dimov
|
2003-08-28 11:14:10 +00:00
|
|
|
// Copyright (c) 2003 Daniel Frey
|
|
|
|
// Copyright (c) 2003 Howard Hinnant
|
2002-05-21 23:39:58 +00:00
|
|
|
//
|
2004-11-20 09:08:45 +00:00
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See
|
|
|
|
// accompanying file LICENSE_1_0.txt or copy at
|
|
|
|
// http://www.boost.org/LICENSE_1_0.txt)
|
2002-05-21 23:39:58 +00:00
|
|
|
//
|
2003-03-03 15:53:48 +00:00
|
|
|
// See http://www.boost.org/libs/utility/checked_delete.html for documentation.
|
|
|
|
//
|
2002-05-21 23:39:58 +00:00
|
|
|
|
|
|
|
namespace boost
|
|
|
|
{
|
|
|
|
|
|
|
|
// verify that types are complete for increased safety
|
|
|
|
|
2003-03-03 15:53:48 +00:00
|
|
|
template<class T> inline void checked_delete(T * x)
|
2002-05-21 23:39:58 +00:00
|
|
|
{
|
2003-08-28 11:14:10 +00:00
|
|
|
// intentionally complex - simplification causes regressions
|
2003-08-07 12:09:24 +00:00
|
|
|
typedef char type_must_be_complete[ sizeof(T)? 1: -1 ];
|
2003-08-28 11:14:10 +00:00
|
|
|
(void) sizeof(type_must_be_complete);
|
2002-05-21 23:39:58 +00:00
|
|
|
delete x;
|
|
|
|
}
|
|
|
|
|
2003-03-03 15:53:48 +00:00
|
|
|
template<class T> inline void checked_array_delete(T * x)
|
2002-05-21 23:39:58 +00:00
|
|
|
{
|
2003-08-07 12:09:24 +00:00
|
|
|
typedef char type_must_be_complete[ sizeof(T)? 1: -1 ];
|
2003-08-28 11:14:10 +00:00
|
|
|
(void) sizeof(type_must_be_complete);
|
2002-05-21 23:39:58 +00:00
|
|
|
delete [] x;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T> struct checked_deleter
|
|
|
|
{
|
|
|
|
typedef void result_type;
|
|
|
|
typedef T * argument_type;
|
|
|
|
|
2003-03-03 15:53:48 +00:00
|
|
|
void operator()(T * x) const
|
2002-05-21 23:39:58 +00:00
|
|
|
{
|
2003-08-07 12:09:24 +00:00
|
|
|
// boost:: disables ADL
|
2003-03-03 15:53:48 +00:00
|
|
|
boost::checked_delete(x);
|
2002-05-21 23:39:58 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class T> struct checked_array_deleter
|
|
|
|
{
|
|
|
|
typedef void result_type;
|
|
|
|
typedef T * argument_type;
|
|
|
|
|
2003-03-03 15:53:48 +00:00
|
|
|
void operator()(T * x) const
|
2002-05-21 23:39:58 +00:00
|
|
|
{
|
2003-03-03 15:53:48 +00:00
|
|
|
boost::checked_array_delete(x);
|
2002-05-21 23:39:58 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace boost
|
|
|
|
|
|
|
|
#endif // #ifndef BOOST_CHECKED_DELETE_HPP_INCLUDED
|