Skip to content

Avoid C style casts in the docs, at least for pointers #2487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/advanced/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ like so:
.. code-block:: cpp

py::class_<MyClass>("MyClass")
.def("myFunction", py::arg("arg") = (SomeType *) nullptr);
.def("myFunction", py::arg("arg") = static_cast<SomeType *>(nullptr));

Keyword-only arguments
======================
Expand Down
4 changes: 2 additions & 2 deletions docs/advanced/misc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ pybind11 version. Consider the following example:

.. code-block:: cpp

auto data = (MyData *) py::get_shared_data("mydata");
auto data = reinterpret_cast<MyData *>(py::get_shared_data("mydata"));
if (!data)
data = (MyData *) py::set_shared_data("mydata", new MyData(42));
data = static_cast<MyData *>(py::set_shared_data("mydata", new MyData(42)));

If the above snippet was used in several separately compiled extension modules,
the first one to be imported would create a ``MyData`` instance and associate
Expand Down
6 changes: 3 additions & 3 deletions docs/advanced/pycpp/numpy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,9 @@ simply using ``vectorize``).

py::buffer_info buf3 = result.request();

double *ptr1 = (double *) buf1.ptr,
*ptr2 = (double *) buf2.ptr,
*ptr3 = (double *) buf3.ptr;
double *ptr1 = static_cast<double *>(buf1.ptr);
double *ptr2 = static_cast<double *>(buf2.ptr);
double *ptr3 = static_cast<double *>(buf3.ptr);

for (size_t idx = 0; idx < buf1.shape[0]; idx++)
ptr3[idx] = ptr1[idx] + ptr2[idx];
Expand Down
4 changes: 2 additions & 2 deletions docs/classes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,8 @@ sequence.

py::class_<Pet>(m, "Pet")
.def(py::init<const std::string &, int>())
.def("set", (void (Pet::*)(int)) &Pet::set, "Set the pet's age")
.def("set", (void (Pet::*)(const std::string &)) &Pet::set, "Set the pet's name");
.def("set", static_cast<void (Pet::*)(int)>(&Pet::set), "Set the pet's age")
.def("set", static_cast<void (Pet::*)(const std::string &)>(&Pet::set), "Set the pet's name");

The overload signatures are also visible in the method's docstring:

Expand Down