Skip to content

Commit 51c833e

Browse files
Explicitly connect smart pointers and holders in the documentation.
1 parent 72dabe3 commit 51c833e

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

docs/advanced/smart_ptrs.rst

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
1-
Smart pointers
2-
##############
1+
.. _holders:
2+
3+
Smart pointers and holders
4+
##########################
5+
6+
Holders
7+
=======
8+
9+
The binding generator for classes, :class:`class_`, can be passed a template
10+
type that denotes a special *holder* type that is used to manage references to
11+
the object. If no such holder type template argument is given, the default for
12+
a type named ``Type`` is ``std::unique_ptr<Type>``, which means that the object
13+
is deallocated when Python's reference count goes to zero. It is possible to
14+
switch to other types of reference counting wrappers or smart pointers, which
15+
is useful in codebases that rely on them, such as ``std::shared_ptr<Type>``, or
16+
even a custom type.
317

418
std::unique_ptr
519
===============
@@ -31,15 +45,10 @@ instance, the object might be referenced elsewhere).
3145
std::shared_ptr
3246
===============
3347

34-
The binding generator for classes, :class:`class_`, can be passed a template
35-
type that denotes a special *holder* type that is used to manage references to
36-
the object. If no such holder type template argument is given, the default for
37-
a type named ``Type`` is ``std::unique_ptr<Type>``, which means that the object
38-
is deallocated when Python's reference count goes to zero.
48+
If you have an existing code base with ``std::shared_ptr``, or you wish to enable
49+
reference counting in C++ as well, then you may use this type as a holder.
3950

40-
It is possible to switch to other types of reference counting wrappers or smart
41-
pointers, which is useful in codebases that rely on them. For instance, the
42-
following snippet causes ``std::shared_ptr`` to be used instead.
51+
As an example, the following snippet causes ``std::shared_ptr`` to be used instead.
4352

4453
.. code-block:: cpp
4554

0 commit comments

Comments
 (0)