`py::smart_holder`'s Unique `shared_ptr` Wrapper for Type Fidelity

`py::smart_holder` prevents inheritance slicing by employing a type-erased wrapper around `std::shared_ptr`. When converting a Python object to `std::shared_ptr<T>`, it creates an independent control block that keeps the *derived* Python object alive, ensuring the correct type information is preserved across the C++ and Python boundary.

Sources

Open the full topic