20 explicit BaseN(
int i) :
i(
i) {}
26 std::string
vanilla() {
return "Vanilla"; };
29 static std::string static_func1() {
return "WithStatic1"; };
30 static int static_value1;
33 static std::string static_func2() {
return "WithStatic2"; };
34 static int static_value2;
36 struct VanillaStaticMix1 : Vanilla, WithStatic1, WithStatic2 {
37 static std::string static_func() {
return "VanillaStaticMix1"; }
38 static int static_value;
40 struct VanillaStaticMix2 : WithStatic1, Vanilla, WithStatic2 {
41 static std::string static_func() {
return "VanillaStaticMix2"; }
42 static int static_value;
44 int WithStatic1::static_value1 = 1;
45 int WithStatic2::static_value2 = 2;
46 int VanillaStaticMix1::static_value = 12;
47 int VanillaStaticMix2::static_value = 12;
51 explicit Base1a(
int i) :
i(
i) {}
52 int foo()
const {
return i; }
56 explicit Base2a(
int i) :
i(
i) {}
57 int bar()
const {
return i; }
60 struct Base12a : Base1a, Base2a {
61 Base12a(
int i,
int j) : Base1a(
i), Base2a(
j) {}
69 I801B1(
const I801B1 &) =
default;
70 virtual ~I801B1() =
default;
75 I801B2(
const I801B2 &) =
default;
76 virtual ~I801B2() =
default;
78 struct I801C : I801B1, I801B2 {};
79 struct I801D : I801C {};
91 explicit Base1(
int i) :
i(
i) {}
92 int foo()
const {
return i; }
95 py::class_<Base1>
b1(
m,
"Base1");
99 explicit Base2(
int i) :
i(
i) {}
100 int bar()
const {
return i; }
103 py::class_<Base2>
b2(
m,
"Base2");
104 b2.def(py::init<int>()).def(
"bar", &Base2::bar);
107 struct Base12 : Base1, Base2 {
108 Base12(
int i,
int j) : Base1(
i), Base2(
j) {}
110 struct MIType : Base12 {
111 MIType(
int i,
int j) : Base12(
i,
j) {}
113 py::class_<Base12, Base1, Base2>(
m,
"Base12");
114 py::class_<MIType, Base12>(
m,
"MIType").def(py::init<int, int>());
117 #define PYBIND11_BASEN(N) \
118 py::class_<BaseN<(N)>>(m, "BaseN" #N).def(py::init<int>()).def("f" #N, [](BaseN<N> &b) { \
151 py::class_<Base1a, std::shared_ptr<Base1a>>(
m,
"Base1a")
152 .def(py::init<int>())
155 py::class_<Base2a, std::shared_ptr<Base2a>>(
m,
"Base2a")
156 .def(py::init<int>())
157 .def(
"bar", &Base2a::bar);
159 py::class_<Base12a, Base2a, std::shared_ptr<Base12a>>(
160 m,
"Base12a", py::multiple_inheritance())
161 .def(py::init<int, int>());
163 m.def(
"bar_base2a", [](Base2a *
b) {
return b->bar(); });
164 m.def(
"bar_base2a_sharedptr", [](
const std::shared_ptr<Base2a> &
b) {
return b->bar(); });
172 virtual ~I801B3() =
default;
174 struct I801E : I801B3, I801D {};
176 py::class_<I801B1, std::shared_ptr<I801B1>>(
m,
"I801B1")
179 py::class_<I801B2, std::shared_ptr<I801B2>>(
m,
"I801B2")
182 py::class_<I801C, I801B1, I801B2, std::shared_ptr<I801C>>(
m,
"I801C").def(py::init<>());
183 py::class_<I801D, I801C, std::shared_ptr<I801D>>(
m,
"I801D").def(py::init<>());
188 m.def(
"i801b1_c", [](I801C *
c) {
return static_cast<I801B1 *
>(
c); });
189 m.def(
"i801b2_c", [](I801C *
c) {
return static_cast<I801B2 *
>(
c); });
190 m.def(
"i801b1_d", [](I801D *
d) {
return static_cast<I801B1 *
>(
d); });
191 m.def(
"i801b2_d", [](I801D *
d) {
return static_cast<I801B2 *
>(
d); });
196 m.def(
"i801c_b1", []() -> I801B1 * {
return new I801C(); });
197 m.def(
"i801c_b2", []() -> I801B2 * {
return new I801C(); });
198 m.def(
"i801d_b1", []() -> I801B1 * {
return new I801D(); });
199 m.def(
"i801d_b2", []() -> I801B2 * {
return new I801D(); });
203 m.def(
"i801e_c", []() -> I801C * {
return new I801E(); });
204 m.def(
"i801e_b2", []() -> I801B2 * {
return new I801E(); });
207 py::class_<Vanilla>(
m,
"Vanilla").def(py::init<>()).def(
"vanilla", &Vanilla::vanilla);
209 py::class_<WithStatic1>(
m,
"WithStatic1")
211 .def_static(
"static_func1", &WithStatic1::static_func1)
212 .def_readwrite_static(
"static_value1", &WithStatic1::static_value1);
214 py::class_<WithStatic2>(
m,
"WithStatic2")
216 .def_static(
"static_func2", &WithStatic2::static_func2)
217 .def_readwrite_static(
"static_value2", &WithStatic2::static_value2);
219 py::class_<VanillaStaticMix1, Vanilla, WithStatic1, WithStatic2>(
m,
"VanillaStaticMix1")
221 .def_static(
"static_func", &VanillaStaticMix1::static_func)
222 .def_readwrite_static(
"static_value", &VanillaStaticMix1::static_value);
224 py::class_<VanillaStaticMix2, WithStatic1, Vanilla, WithStatic2>(
m,
"VanillaStaticMix2")
226 .def_static(
"static_func", &VanillaStaticMix2::static_func)
227 .def_readwrite_static(
"static_value", &VanillaStaticMix2::static_value);
230 struct VanillaDictMix1 : Vanilla, WithDict {};
231 struct VanillaDictMix2 : WithDict, Vanilla {};
232 py::class_<WithDict>(
m,
"WithDict", py::dynamic_attr()).def(py::init<>());
233 py::class_<VanillaDictMix1, Vanilla, WithDict>(
m,
"VanillaDictMix1").def(py::init<>());
234 py::class_<VanillaDictMix2, WithDict, Vanilla>(
m,
"VanillaDictMix2").def(py::init<>());
242 B(
const B &) =
default;
243 virtual ~
B() =
default;
245 struct C0 :
public virtual B {
248 struct C1 :
public virtual B {
251 struct D :
public C0,
public C1 {
254 py::class_<B>(
m,
"B").def(
"b", [](
B *
self) {
return self; });
255 py::class_<C0, B>(
m,
"C0").def(
"c0", [](C0 *
self) {
return self; });
256 py::class_<C1, B>(
m,
"C1").def(
"c1", [](
C1 *
self) {
return self; });
257 py::class_<D, C0, C1>(
m,
"D").def(py::init<>());
263 MVB(
const MVB &) =
default;
264 virtual ~MVB() =
default;
267 int get_b_b()
const {
return b; }
269 struct MVC :
virtual MVB {
271 int get_c_b()
const {
return b; }
272 int get_c_c()
const {
return c; }
274 struct MVD0 :
virtual MVC {
276 int get_d0_b()
const {
return b; }
277 int get_d0_c()
const {
return c; }
278 int get_d0_d0()
const {
return d0; }
280 struct MVD1 :
virtual MVC {
282 int get_d1_b()
const {
return b; }
283 int get_d1_c()
const {
return c; }
284 int get_d1_d1()
const {
return d1; }
286 struct MVE :
virtual MVD0,
virtual MVD1 {
288 int get_e_b()
const {
return b; }
289 int get_e_c()
const {
return c; }
290 int get_e_d0()
const {
return d0; }
291 int get_e_d1()
const {
return d1; }
292 int get_e_e()
const {
return e; }
294 struct MVF :
virtual MVE {
296 int get_f_b()
const {
return b; }
297 int get_f_c()
const {
return c; }
298 int get_f_d0()
const {
return d0; }
299 int get_f_d1()
const {
return d1; }
300 int get_f_e()
const {
return e; }
301 int get_f_f()
const {
return f; }
303 py::class_<MVB>(
m,
"MVB")
305 .def(
"get_b_b", &MVB::get_b_b)
306 .def_readwrite(
"b", &
MVB::b);
307 py::class_<MVC, MVB>(
m,
"MVC")
309 .def(
"get_c_b", &MVC::get_c_b)
310 .def(
"get_c_c", &MVC::get_c_c)
311 .def_readwrite(
"c", &
MVC::c);
312 py::class_<MVD0, MVC>(
m,
"MVD0")
314 .def(
"get_d0_b", &MVD0::get_d0_b)
315 .def(
"get_d0_c", &MVD0::get_d0_c)
316 .def(
"get_d0_d0", &MVD0::get_d0_d0)
317 .def_readwrite(
"d0", &MVD0::d0);
318 py::class_<MVD1, MVC>(
m,
"MVD1")
320 .def(
"get_d1_b", &MVD1::get_d1_b)
321 .def(
"get_d1_c", &MVD1::get_d1_c)
322 .def(
"get_d1_d1", &MVD1::get_d1_d1)
323 .def_readwrite(
"d1", &MVD1::d1);
324 py::class_<MVE, MVD0, MVD1>(
m,
"MVE")
326 .def(
"get_e_b", &MVE::get_e_b)
327 .def(
"get_e_c", &MVE::get_e_c)
328 .def(
"get_e_d0", &MVE::get_e_d0)
329 .def(
"get_e_d1", &MVE::get_e_d1)
330 .def(
"get_e_e", &MVE::get_e_e)
331 .def_readwrite(
"e", &
MVE::e);
332 py::class_<MVF, MVE>(
m,
"MVF")
334 .def(
"get_f_b", &MVF::get_f_b)
335 .def(
"get_f_c", &MVF::get_f_c)
336 .def(
"get_f_d0", &MVF::get_f_d0)
337 .def(
"get_f_d1", &MVF::get_f_d1)
338 .def(
"get_f_e", &MVF::get_f_e)
339 .def(
"get_f_f", &MVF::get_f_f)
340 .def_readwrite(
"f", &
MVF::f);