Skip to content

Commit

Permalink
Suggest smart_holder for "most situations for safety"
Browse files Browse the repository at this point in the history
  • Loading branch information
rwgk committed Mar 1, 2025
1 parent 8409b19 commit e83f3eb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions docs/advanced/smart_ptrs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ simply add ``py::smart_holder`` to ``py::class_``:

.. note::

A shorthand, ``py::classh<T>``, is provided for ``py::class_<T,
py::smart_holder>``. The ``h`` in ``py::classh`` comes from
**smart_holder** but is condensed for brevity; it is the same number of
characters as ``py::class_``.
A shorthand, ``py::classh<T>``, is provided for
``py::class_<T, py::smart_holder>``. The ``h`` in ``py::classh`` stands
for **smart_holder** but is shortened for brevity, ensuring it has the
same number of characters as ``py::class_``. This design choice facilitates
easy experimentation with ``py::smart_holder`` without introducing
distracting whitespace noise in diffs.

The ``py::smart_holder`` functionality includes the following:

Expand Down
4 changes: 2 additions & 2 deletions docs/classes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ constructor (see the :ref:`custom_constructors` section for details).
.. note::

Starting with pybind11v3, it is recommended to include `py::smart_holder`
if you plan to support conversions to C++ smart pointers. See
:ref:`smart_holder` for more information.
in most situations for safety, especially if you plan to support conversions
to C++ smart pointers. See :ref:`smart_holder` for more information.

An interactive Python session demonstrating this example is shown below:

Expand Down

0 comments on commit e83f3eb

Please sign in to comment.