checked_delete.hpp 1.6 KB

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