checked_delete.qbk 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. [/
  2. / Copyright (c) 2002, 2003, 2005 Peter Dimov
  3. / Copyright (c) 2014 Glen Fernandes
  4. /
  5. / Distributed under the Boost Software License, Version 1.0. (See
  6. / accompanying file LICENSE_1_0.txt or copy at
  7. / http://www.boost.org/LICENSE_1_0.txt)
  8. /]
  9. [section:checked_delete checked_delete]
  10. [simplesect Authors]
  11. * Beman Dawes
  12. * Dave Abrahams
  13. * Vladimir Prus
  14. * Rainer Deyke
  15. * John Maddock
  16. [endsimplesect]
  17. [section Overview]
  18. The header `<boost/checked_delete.hpp>` defines two function
  19. templates, `checked_delete` and `checked_array_delete`, and two
  20. class templates, `checked_deleter` and `checked_array_deleter`.
  21. The C++ Standard allows, in 5.3.5/5, pointers to incomplete
  22. class types to be deleted with a delete-expression. When the
  23. class has a non-trivial destructor, or a class-specific
  24. operator delete, the behavior is undefined. Some compilers
  25. issue a warning when an incomplete type is deleted, but
  26. unfortunately, not all do, and programmers sometimes ignore or
  27. disable warnings.
  28. A particularly troublesome case is when a smart pointer's
  29. destructor, such as `boost::scoped_ptr<T>::~scoped_ptr`, is
  30. instantiated with an incomplete type. This can often lead to
  31. silent, hard to track failures.
  32. The supplied function and class templates can be used to
  33. prevent these problems, as they require a complete type, and
  34. cause a compilation error otherwise.
  35. [endsect]
  36. [section Synopsis]
  37. ``
  38. namespace boost
  39. {
  40. template<class T> void checked_delete(T * p);
  41. template<class T> void checked_array_delete(T * p);
  42. template<class T> struct checked_deleter;
  43. template<class T> struct checked_array_deleter;
  44. }
  45. ``
  46. [endsect]
  47. [section checked_delete]
  48. [section template<class T> void checked_delete(T * p);]
  49. * *Requires:* `T` must be a complete type. The expression
  50. `delete p` must be well-formed.
  51. * *Effects:* `delete p;`
  52. [endsect]
  53. [endsect]
  54. [section checked_array_delete]
  55. [section template<class T> void checked_array_delete(T * p);]
  56. * *Requires:* `T` must be a complete type. The expression
  57. `delete [] p` must be well-formed.
  58. * *Effects:* `delete [] p;`
  59. [endsect]
  60. [endsect]
  61. [section checked_deleter]
  62. ``
  63. template<class T> struct checked_deleter
  64. {
  65. typedef void result_type;
  66. typedef T * argument_type;
  67. void operator()(T * p) const;
  68. };
  69. ``
  70. [section void checked_deleter<T>::operator()(T * p) const;]
  71. * *Requires:* `T` must be a complete type. The expression
  72. `delete p` must be well-formed.
  73. * *Effects:* `delete p;`
  74. [endsect]
  75. [endsect]
  76. [section checked_array_deleter]
  77. ``
  78. template<class T> struct checked_array_deleter
  79. {
  80. typedef void result_type;
  81. typedef T * argument_type;
  82. void operator()(T * p) const;
  83. };
  84. ``
  85. [section void checked_array_deleter<T>::operator()(T * p) const;]
  86. * *Requires:* `T` must be a complete type. The expression
  87. `delete [] p` must be well-formed.
  88. * *Effects:* `delete [] p;`
  89. [endsect]
  90. [endsect]
  91. [section Acknowledgements]
  92. The function templates `checked_delete` and
  93. `checked_array_delete` were originally part of
  94. `<boost/utility.hpp>`, and the documentation
  95. acknowledged Beman Dawes, Dave Abrahams,
  96. Vladimir Prus, Rainer Deyke, John Maddock,
  97. and others as contributors.
  98. [endsect]
  99. [endsect]