MCPcopy Create free account
hub / github.com/arximboldi/immer / PYBIND11_PLUGIN

Function PYBIND11_PLUGIN

extra/python/src/immer-pybind.cpp:39–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37namespace py = pybind11;
38
39PYBIND11_PLUGIN(immer_python_module)
40{
41 py::module m("immer", R"pbdoc(
42 Immer
43 -----
44 .. currentmodule:: immer
45 .. autosummary::
46 :toctree: _generate
47 Vector
48 )pbdoc");
49
50 using vector_t = immer::vector<py::object, memory_t>;
51
52 py::class_<vector_t>(m, "Vector")
53 .def(py::init<>())
54 .def("__len__", &vector_t::size)
55 .def("__getitem__",
56 [](const vector_t& v, std::size_t i) {
57 if (i > v.size())
58 throw py::index_error{"Index out of range"};
59 return v[i];
60 })
61 .def("append",
62 [](const vector_t& v, py::object x) {
63 return v.push_back(std::move(x));
64 })
65 .def("set", [](const vector_t& v, std::size_t i, py::object x) {
66 return v.set(i, std::move(x));
67 });
68
69#ifdef VERSION_INFO
70 m.attr("__version__") = py::str(VERSION_INFO);
71#else
72 m.attr("__version__") = py::str("dev");
73#endif
74
75 return m.ptr();
76}

Callers

nothing calls this directly

Calls 3

sizeMethod · 0.45
push_backMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected