#include "pybind11_tests.h" #include #include #include namespace pybind11_tests { using pybind11::vptr; vptr from_raw() { return vptr{new double{3}}; } vptr from_unique() { return vptr{std::unique_ptr(new double{5})}; } vptr from_shared() { return vptr{std::shared_ptr(new double{7})}; } TEST_SUBMODULE(variant_unique_shared, m) { m.def("from_raw", from_raw); m.def("from_unique", from_unique); m.def("from_shared", from_shared); py::class_>(m, "vptr_double") .def(py::init<>()) .def("ownership_type", &vptr::ownership_type) .def("get_value", [](vptr &v) { auto p = v.get(); if (p) return *p; return -1.; }) .def("get_unique", [](vptr &v) { v.get_unique(); return; }) .def("get_shared", [](vptr &v) { v.get_shared(); return; }); } } // namespace pybind11_tests