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 
8 # include <boost/python/detail/type_traits.hpp>
9 # include <boost/detail/workaround.hpp>
10 namespace boost { namespace python { namespace detail {
11 
12 template <bool array> struct value_destroyer;
13 
14 template <>
15 struct value_destroyer<false>
16 {
17     template <class T>
executeboost::python::detail::value_destroyer18     static void execute(T const volatile* p)
19     {
20         p->~T();
21     }
22 };
23 
24 template <>
25 struct value_destroyer<true>
26 {
27     template <class A, class T>
executeboost::python::detail::value_destroyer28     static void execute(A*, T const volatile* const first)
29     {
30         for (T const volatile* p = first; p != first + sizeof(A)/sizeof(T); ++p)
31         {
32             value_destroyer<
33                 is_array<T>::value
34             >::execute(p);
35         }
36     }
37 
38     template <class T>
executeboost::python::detail::value_destroyer39     static void execute(T const volatile* p)
40     {
41         execute(p, *p);
42     }
43 };
44 
45 template <class T>
destroy_referent_impl(void * p,T & (*)())46 inline void destroy_referent_impl(void* p, T& (*)())
47 {
48     // note: cv-qualification needed for MSVC6
49     // must come *before* T for metrowerks
50     value_destroyer<
51          (is_array<T>::value)
52     >::execute((const volatile T*)p);
53 }
54 
55 template <class T>
destroy_referent(void * p,T (*)()=0)56 inline void destroy_referent(void* p, T(*)() = 0)
57 {
58     destroy_referent_impl(p, (T(*)())0);
59 }
60 
61 }}} // namespace boost::python::detail
62 
63 #endif // DESTROY_DWA2002221_HPP
64