MCPcopy Create free account
hub / github.com/pybind/pybind11 / cast

Function cast

tests/test_docs_advanced_cast_custom.cpp:34–37  ·  view source on GitHub ↗

C++ -> Python: convert `Point2D` to `tuple[float, float]`. The second and third arguments are used to indicate the return value policy and parent object (for return_value_policy::reference_internal) and are often ignored by custom casters. The return value should reflect the type hint specified by the second argument of `io_name`.

Source from the content-addressed store, hash-verified

32 // return_value_policy::reference_internal) and are often ignored by custom casters.
33 // The return value should reflect the type hint specified by the second argument of `io_name`.
34 static handle
35 cast(const user_space::Point2D &number, return_value_policy /*policy*/, handle /*parent*/) {
36 return py::make_tuple(number.x, number.y).release();
37 }
38
39 // Python -> C++: convert a `PyObject` into a `Point2D` and return false upon failure. The
40 // second argument indicates whether implicit conversions should be allowed.

Callers 15

contextEnterMethod · 0.70
py_cast_VectorOwner_ptrFunction · 0.70
TEST_SUBMODULEFunction · 0.70
TEST_SUBMODULEFunction · 0.70
castMethod · 0.70
castMethod · 0.70
castMethod · 0.70
CastUnusualOpRefConstRefFunction · 0.70
CastUnusualOpRefMovableFunction · 0.70
TEST_SUBMODULEFunction · 0.70
valuesMethod · 0.70
TEST_SUBMODULEFunction · 0.70

Calls 2

make_tupleFunction · 0.85
releaseMethod · 0.80

Tested by

no test coverage detected