Template Class PySharedPtr

Class Documentation

template<typename T>
class PySharedPtr

A shared pointer that tracks both a C++ object and its associated PyObject.

Each group of PySharedPtr for a given object collectively counts as one reference to that object for the purpose of Python garbage collection.

A PySharedPtr is implicitly convertible to and from a std::shared_ptr to minimize API impact. Any shared_ptr created this way will (I think) keep the Python reference alive, as described above.

Public Types

template<>
using element_type = T

Public Functions

PySharedPtr(T *const ptr)

Create a pointer that counts as an extra reference in the Python environment.

Parameters
  • ptr: a pointer to a pybind11-managed object.

PySharedPtr(PySharedPtr const&)
PySharedPtr(PySharedPtr&&)
PySharedPtr &operator=(PySharedPtr const&)
PySharedPtr &operator=(PySharedPtr&&)
~PySharedPtr()
PySharedPtr(std::shared_ptr<T> r)
operator std::shared_ptr<T>()
T *get() const