| 231 | void initialize_inherited_virtuals(py::module_ &m); |
| 232 | |
| 233 | TEST_SUBMODULE(virtual_functions, m) { |
| 234 | // test_override |
| 235 | py::class_<ExampleVirt, PyExampleVirt>(m, "ExampleVirt") |
| 236 | .def(py::init<int>()) |
| 237 | /* Reference original class in function definitions */ |
| 238 | .def("run", &ExampleVirt::run) |
| 239 | .def("run_bool", &ExampleVirt::run_bool) |
| 240 | .def("pure_virtual", &ExampleVirt::pure_virtual); |
| 241 | |
| 242 | py::class_<NonCopyable>(m, "NonCopyable").def(py::init<int, int>()); |
| 243 | |
| 244 | py::class_<Movable>(m, "Movable").def(py::init<int, int>()); |
| 245 | |
| 246 | // test_move_support |
| 247 | #if !defined(__INTEL_COMPILER) && !defined(__CUDACC__) && !defined(__PGIC__) |
| 248 | py::class_<NCVirt, NCVirtTrampoline>(m, "NCVirt") |
| 249 | .def(py::init<>()) |
| 250 | .def("get_noncopyable", &NCVirt::get_noncopyable) |
| 251 | .def("get_movable", &NCVirt::get_movable) |
| 252 | .def("print_nc", &NCVirt::print_nc) |
| 253 | .def("print_movable", &NCVirt::print_movable); |
| 254 | #endif |
| 255 | |
| 256 | m.def("runExampleVirt", [](ExampleVirt *ex, int value) { return ex->run(value); }); |
| 257 | m.def("runExampleVirtBool", [](ExampleVirt *ex) { return ex->run_bool(); }); |
| 258 | m.def("runExampleVirtVirtual", [](ExampleVirt *ex) { ex->pure_virtual(); }); |
| 259 | |
| 260 | m.def("cstats_debug", &ConstructorStats::get<ExampleVirt>); |
| 261 | initialize_inherited_virtuals(m); |
| 262 | |
| 263 | // test_alias_delay_initialization1 |
| 264 | // don't invoke Python dispatch classes by default when instantiating C++ classes |
| 265 | // that were not extended on the Python side |
| 266 | struct A { |
| 267 | A() = default; |
| 268 | A(const A &) = delete; |
| 269 | virtual ~A() = default; |
| 270 | virtual void f() { py::print("A.f()"); } |
| 271 | }; |
| 272 | |
| 273 | struct PyA : A { |
| 274 | PyA() { py::print("PyA.PyA()"); } |
| 275 | PyA(const PyA &) = delete; |
| 276 | ~PyA() override { py::print("PyA.~PyA()"); } |
| 277 | |
| 278 | void f() override { |
| 279 | py::print("PyA.f()"); |
| 280 | // This convolution just gives a `void`, but tests that PYBIND11_TYPE() works to |
| 281 | // protect a type containing a , |
| 282 | PYBIND11_OVERRIDE(PYBIND11_TYPE(typename std::enable_if<true, void>::type), A, f); |
| 283 | } |
| 284 | }; |
| 285 | |
| 286 | py::class_<A, PyA>(m, "A").def(py::init<>()).def("f", &A::f); |
| 287 | |
| 288 | m.def("call_f", [](A *a) { a->f(); }); |
| 289 | |
| 290 | // test_alias_delay_initialization2 |
nothing calls this directly
no test coverage detected