Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/python/test/destroy_test.cpp @ 12

Last change on this file since 12 was 12, checked in by landauf, 17 years ago

added boost

File size: 1.0 KB
Line 
1// Copyright David Abrahams 2004. Distributed under the Boost
2// Software License, Version 1.0. (See accompanying
3// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4#include <boost/python/detail/destroy.hpp>
5#include <cassert>
6
7int count;
8int marks[] = {
9    -1
10    , -1, -1
11    , -1, -1, -1, -1
12    , -1
13};
14int* kills = marks;
15
16struct foo
17{
18    foo() : n(count++) {}
19    ~foo()
20    {
21        *kills++ = n;
22    }
23    int n;
24};
25
26void assert_destructions(int n)
27{
28    for (int i = 0; i < n; ++i)
29        assert(marks[i] == i);
30    assert(marks[n] == -1);
31}
32
33int main()
34{
35    assert_destructions(0);
36    typedef int a[2];
37   
38    foo* f1 = new foo;
39    boost::python::detail::destroy_referent<foo const volatile&>(f1);
40    assert_destructions(1);
41   
42    foo* f2 = new foo[2];
43    typedef foo x[2];
44   
45    boost::python::detail::destroy_referent<x const&>(f2);
46    assert_destructions(3);
47
48    typedef foo y[2][2];
49    x* f3 = new y;
50    boost::python::detail::destroy_referent<y&>(f3);
51    assert_destructions(7);
52
53    return 0;
54}
Note: See TracBrowser for help on using the repository browser.