From 149e332b3e25a6c8963bbdd845b329839f71fd66 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Thu, 28 Jan 2021 18:34:59 -0800 Subject: [PATCH] Adding classu alias for class_>. --- include/pybind11/smart_holder.h | 8 ++++++++ tests/test_class_sh_unique_ptr_member.cpp | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/pybind11/smart_holder.h b/include/pybind11/smart_holder.h index 25f0e6b52..7d7e9f03e 100644 --- a/include/pybind11/smart_holder.h +++ b/include/pybind11/smart_holder.h @@ -19,4 +19,12 @@ public: using class_::class_; }; +// Similar in idea to `py::classh`, but for `std::unique_ptr` holder, to support +// an easier transition to `py::smart_holder` as default holder. +template +class classu : public class_, options...> { +public: + using class_, options...>::class_; +}; + PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/tests/test_class_sh_unique_ptr_member.cpp b/tests/test_class_sh_unique_ptr_member.cpp index a34274a0c..cb3865136 100644 --- a/tests/test_class_sh_unique_ptr_member.cpp +++ b/tests/test_class_sh_unique_ptr_member.cpp @@ -50,7 +50,8 @@ TEST_SUBMODULE(class_sh_unique_ptr_member, m) { m.def("make_unique_pointee", make_unique_pointee); - py::class_(m, "ptr_owner") + // Could also be class_, but can conveniently be used for testing classu. + py::classu(m, "ptr_owner") .def(py::init>(), py::arg("ptr")) .def("is_owner", &ptr_owner::is_owner) .def("give_up_ownership_via_unique_ptr", &ptr_owner::give_up_ownership_via_unique_ptr)