mirror of
https://github.com/pybind/pybind11.git
synced 2025-02-07 17:32:00 +00:00
Adding classu alias for class_<U, std::unique_ptr<U>>.
This commit is contained in:
parent
1e4c2e04ae
commit
149e332b3e
@ -19,4 +19,12 @@ public:
|
||||
using class_<type_, smart_holder, options...>::class_;
|
||||
};
|
||||
|
||||
// Similar in idea to `py::classh`, but for `std::unique_ptr<U>` holder, to support
|
||||
// an easier transition to `py::smart_holder` as default holder.
|
||||
template <typename type_, typename... options>
|
||||
class classu : public class_<type_, std::unique_ptr<type_>, options...> {
|
||||
public:
|
||||
using class_<type_, std::unique_ptr<type_>, options...>::class_;
|
||||
};
|
||||
|
||||
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
|
||||
|
@ -50,7 +50,8 @@ TEST_SUBMODULE(class_sh_unique_ptr_member, m) {
|
||||
|
||||
m.def("make_unique_pointee", make_unique_pointee);
|
||||
|
||||
py::class_<ptr_owner>(m, "ptr_owner")
|
||||
// Could also be class_, but can conveniently be used for testing classu.
|
||||
py::classu<ptr_owner>(m, "ptr_owner")
|
||||
.def(py::init<std::unique_ptr<pointee>>(), 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)
|
||||
|
Loading…
Reference in New Issue
Block a user