1
2 #include <boost/parameter.hpp>
3
4 namespace boost { namespace python {
5
6 BOOST_PARAMETER_TEMPLATE_KEYWORD(class_type)
7 BOOST_PARAMETER_TEMPLATE_KEYWORD(base_list)
8 BOOST_PARAMETER_TEMPLATE_KEYWORD(held_type)
9 BOOST_PARAMETER_TEMPLATE_KEYWORD(copyable)
10
11 template <typename B = int>
12 struct bases
13 {
14 };
15 }}
16
17 #include <boost/mpl/bool.hpp>
18 #include <boost/mpl/placeholders.hpp>
19 #include <boost/mpl/if.hpp>
20 #include <boost/mpl/is_sequence.hpp>
21 #include <boost/type_traits/is_class.hpp>
22 #include <boost/config.hpp>
23
24 #if !defined(BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION) || \
25 !(1 == BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION)
26 #include <boost/type_traits/is_scalar.hpp>
27 #endif
28
29 namespace boost { namespace python {
30
31 typedef boost::parameter::parameters<
32 boost::parameter::required<
33 tag::class_type
34 #if defined(BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION) && \
35 (1 == BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION)
36 , boost::mpl::if_<
37 boost::is_class<boost::mpl::_>
38 , boost::mpl::true_
39 , boost::mpl::false_
40 >
41 #else
42 , boost::mpl::if_<
43 boost::is_scalar<boost::mpl::_>
44 , boost::mpl::false_
45 , boost::mpl::true_
46 >
47 #endif
48 >
49 , boost::parameter::optional<
50 tag::base_list
51 , boost::mpl::is_sequence<boost::mpl::_>
52 >
53 , boost::parameter::optional<tag::held_type>
54 , boost::parameter::optional<tag::copyable>
55 > class_signature;
56 }} // namespace boost::python
57
58 namespace boost { namespace python {
59
60 template <
61 typename A0
62 , typename A1 = boost::parameter::void_
63 , typename A2 = boost::parameter::void_
64 , typename A3 = boost::parameter::void_
65 >
66 struct class_
67 {
68 // Create ArgumentPack
69 typedef typename class_signature::BOOST_NESTED_TEMPLATE bind<
70 A0, A1, A2, A3
71 >::type args;
72
73 // Extract first logical parameter.
74 typedef typename boost::parameter::value_type<
75 args, tag::class_type
76 >::type class_type;
77
78 typedef typename boost::parameter::value_type<
79 args, tag::base_list, boost::python::bases<>
80 >::type base_list;
81
82 typedef typename boost::parameter::value_type<
83 args, tag::held_type, class_type
84 >::type held_type;
85
86 typedef typename boost::parameter::value_type<
87 args, tag::copyable, void
88 >::type copyable;
89 };
90 }} // namespace boost::python
91
92 struct B
93 {
94 };
95
96 struct D
97 {
98 };
99
100 #include <boost/noncopyable.hpp>
101 #include <memory>
102
103 typedef boost::python::class_<
104 boost::python::class_type<B>
105 , boost::python::copyable<boost::noncopyable>
106 > c1;
107
108 typedef boost::python::class_<
109 D
110 , boost::python::held_type<
111 #if defined(BOOST_NO_CXX11_SMART_PTR)
112 std::auto_ptr<D>
113 #else
114 std::unique_ptr<D>
115 #endif
116 >
117 , boost::python::base_list<boost::python::bases<B> >
118 > c2;
119
120 #include <boost/type_traits/is_same.hpp>
121 #include <boost/mpl/aux_/test.hpp>
122 #include <boost/mpl/assert.hpp>
123
MPL_TEST_CASE()124 MPL_TEST_CASE()
125 {
126 BOOST_MPL_ASSERT((
127 boost::mpl::if_<
128 boost::is_same<c1::class_type,B>
129 , boost::mpl::true_
130 , boost::mpl::false_
131 >::type
132 ));
133 BOOST_MPL_ASSERT((
134 boost::mpl::if_<
135 boost::is_same<c1::base_list,boost::python::bases<> >
136 , boost::mpl::true_
137 , boost::mpl::false_
138 >::type
139 ));
140 BOOST_MPL_ASSERT((
141 boost::mpl::if_<
142 boost::is_same<c1::held_type,B>
143 , boost::mpl::true_
144 , boost::mpl::false_
145 >::type
146 ));
147 BOOST_MPL_ASSERT((
148 boost::mpl::if_<
149 boost::is_same<c1::copyable,boost::noncopyable>
150 , boost::mpl::true_
151 , boost::mpl::false_
152 >::type
153 ));
154 BOOST_MPL_ASSERT((
155 boost::mpl::if_<
156 boost::is_same<c2::class_type,D>
157 , boost::mpl::true_
158 , boost::mpl::false_
159 >::type
160 ));
161 BOOST_MPL_ASSERT((
162 boost::mpl::if_<
163 boost::is_same<c2::base_list,boost::python::bases<B> >
164 , boost::mpl::true_
165 , boost::mpl::false_
166 >::type
167 ));
168 #if defined(BOOST_NO_CXX11_SMART_PTR)
169 BOOST_MPL_ASSERT((
170 boost::mpl::if_<
171 boost::is_same<c2::held_type,std::auto_ptr<D> >
172 , boost::mpl::true_
173 , boost::mpl::false_
174 >::type
175 ));
176 #else
177 BOOST_MPL_ASSERT((
178 boost::mpl::if_<
179 boost::is_same<c2::held_type,std::unique_ptr<D> >
180 , boost::mpl::true_
181 , boost::mpl::false_
182 >::type
183 ));
184 #endif // BOOST_NO_CXX11_SMART_PTR
185 BOOST_MPL_ASSERT((
186 boost::mpl::if_<
187 boost::is_same<c2::copyable,void>
188 , boost::mpl::true_
189 , boost::mpl::false_
190 >::type
191 ));
192 }
193
194