forked from pybind/python_example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
35 lines (26 loc) · 665 Bytes
/
main.cpp
File metadata and controls
35 lines (26 loc) · 665 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/stl_bind.h>
struct Foo {
int x;
};
struct Bar {
std::vector<Foo> foos;
};
struct Baz {
std::vector<int> ints;
};
PYBIND11_MAKE_OPAQUE(std::vector<Foo>)
namespace py = pybind11;
PYBIND11_MODULE(python_example, m) {
py::bind_vector<std::vector<Foo>>(m, "VectorFoo");
py::class_<Foo>(m, "Foo")
.def(py::init<>())
.def_readwrite("x", &Foo::x);
py::class_<Bar>(m, "Bar")
.def(py::init<>())
.def_readwrite("foos", &Bar::foos);
py::class_<Baz>(m, "Baz")
.def(py::init<>())
.def_readwrite("ints", &Baz::ints);
}