destroy.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright David Abrahams 2002.
  2. // Distributed under the Boost Software License, Version 1.0. (See
  3. // accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef DESTROY_DWA2002221_HPP
  6. # define DESTROY_DWA2002221_HPP
  7. # include <boost/python/detail/type_traits.hpp>
  8. # include <boost/detail/workaround.hpp>
  9. namespace boost { namespace python { namespace detail {
  10. template <bool array> struct value_destroyer;
  11. template <>
  12. struct value_destroyer<false>
  13. {
  14. template <class T>
  15. static void execute(T const volatile* p)
  16. {
  17. p->~T();
  18. }
  19. };
  20. template <>
  21. struct value_destroyer<true>
  22. {
  23. template <class A, class T>
  24. static void execute(A*, T const volatile* const first)
  25. {
  26. for (T const volatile* p = first; p != first + sizeof(A)/sizeof(T); ++p)
  27. {
  28. value_destroyer<
  29. is_array<T>::value
  30. >::execute(p);
  31. }
  32. }
  33. template <class T>
  34. static void execute(T const volatile* p)
  35. {
  36. execute(p, *p);
  37. }
  38. };
  39. template <class T>
  40. inline void destroy_referent_impl(void* p, T& (*)())
  41. {
  42. // note: cv-qualification needed for MSVC6
  43. // must come *before* T for metrowerks
  44. value_destroyer<
  45. (is_array<T>::value)
  46. >::execute((const volatile T*)p);
  47. }
  48. template <class T>
  49. inline void destroy_referent(void* p, T(*)() = 0)
  50. {
  51. destroy_referent_impl(p, (T(*)())0);
  52. }
  53. }}} // namespace boost::python::detail
  54. #endif // DESTROY_DWA2002221_HPP