23 std::string
vanilla() {
return "Vanilla"; };
34 static std::string
static_func() {
return "VanillaStaticMix1"; }
38 static std::string
static_func() {
return "VanillaStaticMix2"; }
51 Base1(
int i) :
i(
i) { }
52 int foo() {
return i; }
55 py::class_<Base1> b1(
m,
"Base1");
56 b1.def(py::init<int>())
57 .def(
"foo", &Base1::foo);
60 Base2(
int i) :
i(
i) { }
61 int bar() {
return i; }
64 py::class_<Base2> b2(
m,
"Base2");
65 b2.def(py::init<int>())
66 .def(
"bar", &Base2::bar);
70 struct Base12 : Base1, Base2 {
71 Base12(
int i,
int j) : Base1(
i), Base2(j) { }
73 struct MIType : Base12 {
74 MIType(
int i,
int j) : Base12(
i, j) { }
76 py::class_<Base12, Base1, Base2>(
m,
"Base12");
77 py::class_<MIType, Base12>(
m,
"MIType")
78 .def(py::init<int, int>());
82 #define PYBIND11_BASEN(N) py::class_<BaseN<N>>(m, "BaseN" #N).def(py::init<int>()).def("f" #N, [](BaseN<N> &b) { return b.i + N; })
103 Base1a(
int i) :
i(
i) { }
104 int foo() {
return i; }
107 py::class_<Base1a, std::shared_ptr<Base1a>>(
m,
"Base1a")
108 .
def(py::init<int>())
109 .
def(
"foo", &Base1a::foo);
112 Base2a(
int i) :
i(
i) { }
113 int bar() {
return i; }
116 py::class_<Base2a, std::shared_ptr<Base2a>>(
m,
"Base2a")
117 .
def(py::init<int>())
118 .
def(
"bar", &Base2a::bar);
120 struct Base12a : Base1a, Base2a {
121 Base12a(
int i,
int j) : Base1a(
i), Base2a(j) { }
123 py::class_<Base12a, Base2a,
124 std::shared_ptr<Base12a>>(
m,
"Base12a", py::multiple_inheritance())
125 .
def(py::init<int, int>());
127 m.def(
"bar_base2a", [](Base2a *b) {
return b->bar(); });
128 m.def(
"bar_base2a_sharedptr", [](std::shared_ptr<Base2a> b) {
return b->bar(); });
133 struct I801B1 {
int a = 1; I801B1() =
default; I801B1(
const I801B1 &) =
default;
virtual ~I801B1() =
default; };
134 struct I801B2 {
int b = 2; I801B2() =
default; I801B2(
const I801B2 &) =
default;
virtual ~I801B2() =
default; };
135 struct I801C : I801B1, I801B2 {};
136 struct I801D : I801C {};
138 struct I801B3 {
int c = 3;
virtual ~I801B3() =
default; };
139 struct I801E : I801B3, I801D {};
141 py::class_<I801B1, std::shared_ptr<I801B1>>(
m,
"I801B1").
def(py::init<>()).def_readonly(
"a", &I801B1::a);
142 py::class_<I801B2, std::shared_ptr<I801B2>>(
m,
"I801B2").
def(py::init<>()).def_readonly(
"b", &I801B2::b);
143 py::class_<I801C, I801B1, I801B2, std::shared_ptr<I801C>>(
m,
"I801C").
def(py::init<>());
144 py::class_<I801D, I801C, std::shared_ptr<I801D>>(
m,
"I801D").
def(py::init<>());
149 m.def(
"i801b1_c", [](I801C *c) {
return static_cast<I801B1 *
>(c); });
150 m.def(
"i801b2_c", [](I801C *c) {
return static_cast<I801B2 *
>(c); });
151 m.def(
"i801b1_d", [](I801D *d) {
return static_cast<I801B1 *
>(d); });
152 m.def(
"i801b2_d", [](I801D *d) {
return static_cast<I801B2 *
>(d); });
157 m.def(
"i801c_b1", []() -> I801B1 * {
return new I801C(); });
158 m.def(
"i801c_b2", []() -> I801B2 * {
return new I801C(); });
159 m.def(
"i801d_b1", []() -> I801B1 * {
return new I801D(); });
160 m.def(
"i801d_b2", []() -> I801B2 * {
return new I801D(); });
164 m.def(
"i801e_c", []() -> I801C * {
return new I801E(); });
165 m.def(
"i801e_b2", []() -> I801B2 * {
return new I801E(); });
169 py::class_<Vanilla>(
m,
"Vanilla")
173 py::class_<WithStatic1>(
m,
"WithStatic1")
178 py::class_<WithStatic2>(
m,
"WithStatic2")
183 py::class_<VanillaStaticMix1, Vanilla, WithStatic1, WithStatic2>(
184 m,
"VanillaStaticMix1")
189 py::class_<VanillaStaticMix2, WithStatic1, Vanilla, WithStatic2>(
190 m,
"VanillaStaticMix2")
197 struct VanillaDictMix1 :
Vanilla, WithDict { };
198 struct VanillaDictMix2 : WithDict,
Vanilla { };
199 py::class_<WithDict>(
m,
"WithDict", py::dynamic_attr()).def(py::init<>());
200 py::class_<VanillaDictMix1, Vanilla, WithDict>(
m,
"VanillaDictMix1").def(py::init<>());
201 py::class_<VanillaDictMix2, WithDict, Vanilla>(
m,
"VanillaDictMix2").def(py::init<>());
206 struct B {
int b;
B() =
default;
B(
const B&) =
default;
virtual ~
B() =
default; };
207 struct C0 :
public virtual B {
int c0; };
208 struct C1 :
public virtual B {
int c1; };
209 struct D :
public C0,
public C1 {
int d; };
210 py::class_<B>(
m,
"B")
211 .def(
"b", [](
B *
self) {
return self; });
212 py::class_<C0, B>(
m,
"C0")
213 .def(
"c0", [](C0 *
self) {
return self; });
214 py::class_<C1, B>(
m,
"C1")
215 .def(
"c1", [](
C1 *
self) {
return self; });
216 py::class_<D, C0, C1>(
m,
"D")