Commit 979d75de by Sergei Izmailov Committed by Wenzel Jakob

doc: Add note about casting from `None` to `T*` (#1760)

* doc: Add note about casting from `None` to `T*`

* doc: reword 'none-to-pointer' note message

* doc: mention opaque types in 'none-to-pointer' note message
parent 30c03523
...@@ -467,6 +467,15 @@ dog)"``, while attempting to call ``meow(None)`` will raise a ``TypeError``: ...@@ -467,6 +467,15 @@ dog)"``, while attempting to call ``meow(None)`` will raise a ``TypeError``:
The default behaviour when the tag is unspecified is to allow ``None``. The default behaviour when the tag is unspecified is to allow ``None``.
.. note::
Even when ``.none(true)`` is specified for an argument, ``None`` will be converted to a
``nullptr`` *only* for custom and :ref:`opaque <opaque>` types. Pointers to built-in types
(``double *``, ``int *``, ...) and STL types (``std::vector<T> *``, ...; if ``pybind11/stl.h``
is included) are copied when converted to C++ (see :doc:`/advanced/cast/overview`) and will
not allow ``None`` as argument. To pass optional argument of these copied types consider
using ``std::optional<T>``
Overload resolution order Overload resolution order
========================= =========================
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment