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

Method cast

include/pybind11/stl.h:343–358  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

341public:
342 template <typename T>
343 static handle cast(T &&src, return_value_policy policy, handle parent) {
344 if (!std::is_lvalue_reference<T>::value) {
345 policy = return_value_policy_override<Value>::policy(policy);
346 }
347 list l(src.size());
348 ssize_t index = 0;
349 for (auto &&value : src) {
350 auto value_ = reinterpret_steal<object>(
351 value_conv::cast(detail::forward_like<T>(value), policy, parent));
352 if (!value_) {
353 return handle();
354 }
355 PyList_SET_ITEM(l.ptr(), index++, value_.release().ptr()); // steals a reference
356 }
357 return l.release();
358 }
359
360 PYBIND11_TYPE_CASTER(Type,
361 io_name("collections.abc.Sequence", "list") + const_name("[")

Callers

nothing calls this directly

Calls 5

ptrMethod · 0.80
releaseMethod · 0.80
castFunction · 0.70
handleFunction · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected