Skip to content
Discussion options

You must be logged in to vote

The documented custom-holder mechanism is separate from py::smart_holder's built-in conversions. Having a std::shared_ptr-like interface doesn't by itself add your pointer type to smart_holder.

If you want to keep your pointer as the holder, the supported pattern is:

// At global scope, after declaring MySharedPtr and before the bindings:
PYBIND11_DECLARE_HOLDER_TYPE(T, MySharedPtr<T>);

// Inside the module bindings:
py::class_<Widget, MySharedPtr<Widget>>(m, "Widget");

This uses MySharedPtr<Widget> as the holder; it does not extend py::smart_holder. The custom smart pointers documentation covers the expected .get() interface and holder_helper for other accessors. A bound C++ type and it…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by henryiii
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants