checked_delete.hpp 1.6 KB

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