Skip to content

Commit fefd594

Browse files
committed
Avoid C-style casts for pointers in docs
Why only for pointers? Because C casts are hard to grep for.
1 parent cc982ac commit fefd594

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

docs/advanced/functions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ like so:
360360
.. code-block:: cpp
361361
362362
py::class_<MyClass>("MyClass")
363-
.def("myFunction", py::arg("arg") = (SomeType *) nullptr);
363+
.def("myFunction", py::arg("arg") = static_cast<SomeType *>(nullptr));
364364
365365
Keyword-only arguments
366366
======================

docs/advanced/misc.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ pybind11 version. Consider the following example:
176176

177177
.. code-block:: cpp
178178
179-
auto data = (MyData *) py::get_shared_data("mydata");
179+
auto data = reinterpret_cast<MyData *>(py::get_shared_data("mydata"));
180180
if (!data)
181-
data = (MyData *) py::set_shared_data("mydata", new MyData(42));
181+
data = static_cast<MyData *>(py::set_shared_data("mydata", new MyData(42)));
182182
183183
If the above snippet was used in several separately compiled extension modules,
184184
the first one to be imported would create a ``MyData`` instance and associate

docs/advanced/pycpp/numpy.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,9 @@ simply using ``vectorize``).
274274
275275
py::buffer_info buf3 = result.request();
276276
277-
double *ptr1 = (double *) buf1.ptr,
278-
*ptr2 = (double *) buf2.ptr,
279-
*ptr3 = (double *) buf3.ptr;
277+
double *ptr1 = static_cast<double *>(buf1.ptr),
278+
*ptr2 = static_cast<double *>(buf2.ptr),
279+
*ptr3 = static_cast<double *>(buf3.ptr);
280280
281281
for (size_t idx = 0; idx < buf1.shape[0]; idx++)
282282
ptr3[idx] = ptr1[idx] + ptr2[idx];

docs/classes.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,8 @@ sequence.
373373
374374
py::class_<Pet>(m, "Pet")
375375
.def(py::init<const std::string &, int>())
376-
.def("set", (void (Pet::*)(int)) &Pet::set, "Set the pet's age")
377-
.def("set", (void (Pet::*)(const std::string &)) &Pet::set, "Set the pet's name");
376+
.def("set", static_cast<void (Pet::*)(int)>(&Pet::set), "Set the pet's age")
377+
.def("set", static_cast<void (Pet::*)(const std::string &)>(&Pet::set), "Set the pet's name");
378378
379379
The overload signatures are also visible in the method's docstring:
380380

0 commit comments

Comments
 (0)