]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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/type_traits/is_array.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> | |
18 | 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> | |
28 | 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 | boost::is_array<T>::value | |
34 | >::execute(p); | |
35 | } | |
36 | } | |
37 | ||
38 | template <class T> | |
39 | static void execute(T const volatile* p) | |
40 | { | |
41 | execute(p, *p); | |
42 | } | |
43 | }; | |
44 | ||
45 | template <class 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 | (boost::is_array<T>::value) | |
52 | >::execute((const volatile T*)p); | |
53 | } | |
54 | ||
55 | template <class T> | |
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 |