|
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. |
3 | 17 |
|
4 | 18 | std::unique_ptr
|
5 | 19 | ===============
|
@@ -31,15 +45,10 @@ instance, the object might be referenced elsewhere).
|
31 | 45 | std::shared_ptr
|
32 | 46 | ===============
|
33 | 47 |
|
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. |
39 | 50 |
|
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. |
43 | 52 |
|
44 | 53 | .. code-block:: cpp
|
45 | 54 |
|
|
0 commit comments