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 | #include <boost/python/object/class_metadata.hpp> |
---|
6 | #include <boost/python/has_back_reference.hpp> |
---|
7 | #include <boost/python/detail/not_specified.hpp> |
---|
8 | #include <boost/static_assert.hpp> |
---|
9 | #include <boost/type_traits/same_traits.hpp> |
---|
10 | #include <boost/function/function0.hpp> |
---|
11 | #include <boost/mpl/bool.hpp> |
---|
12 | #include <memory> |
---|
13 | |
---|
14 | struct BR {}; |
---|
15 | |
---|
16 | struct Base {}; |
---|
17 | struct Derived : Base {}; |
---|
18 | |
---|
19 | namespace boost { namespace python |
---|
20 | { |
---|
21 | // specialization |
---|
22 | template <> |
---|
23 | struct has_back_reference<BR> |
---|
24 | : mpl::true_ |
---|
25 | { |
---|
26 | }; |
---|
27 | }} // namespace boost::python |
---|
28 | |
---|
29 | template <class T, class U> |
---|
30 | void assert_same(U* = 0, T* = 0) |
---|
31 | { |
---|
32 | BOOST_STATIC_ASSERT((boost::is_same<T,U>::value)); |
---|
33 | |
---|
34 | } |
---|
35 | |
---|
36 | template <class T, class Held, class Holder> |
---|
37 | void assert_holder(T* = 0, Held* = 0, Holder* = 0) |
---|
38 | { |
---|
39 | using namespace boost::python::detail; |
---|
40 | using namespace boost::python::objects; |
---|
41 | |
---|
42 | typedef typename class_metadata< |
---|
43 | T,Held,not_specified,not_specified |
---|
44 | >::holder h; |
---|
45 | |
---|
46 | assert_same<Holder>( |
---|
47 | (h*)0 |
---|
48 | ); |
---|
49 | } |
---|
50 | |
---|
51 | int test_main(int, char * []) |
---|
52 | { |
---|
53 | using namespace boost::python::detail; |
---|
54 | using namespace boost::python::objects; |
---|
55 | |
---|
56 | assert_holder<Base,not_specified,value_holder<Base> >(); |
---|
57 | |
---|
58 | assert_holder<BR,not_specified,value_holder_back_reference<BR,BR> >(); |
---|
59 | assert_holder<Base,Base,value_holder_back_reference<Base,Base> >(); |
---|
60 | assert_holder<BR,BR,value_holder_back_reference<BR,BR> >(); |
---|
61 | |
---|
62 | assert_holder<Base,Derived |
---|
63 | ,value_holder_back_reference<Base,Derived> >(); |
---|
64 | |
---|
65 | assert_holder<Base,std::auto_ptr<Base> |
---|
66 | ,pointer_holder<std::auto_ptr<Base>,Base> >(); |
---|
67 | |
---|
68 | assert_holder<Base,std::auto_ptr<Derived> |
---|
69 | ,pointer_holder_back_reference<std::auto_ptr<Derived>,Base> >(); |
---|
70 | |
---|
71 | assert_holder<BR,std::auto_ptr<BR> |
---|
72 | ,pointer_holder_back_reference<std::auto_ptr<BR>,BR> > (); |
---|
73 | |
---|
74 | return 0; |
---|
75 | } |
---|
76 | |
---|