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

Method cast

include/pybind11/stl.h:271–290  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

269
270 template <typename T>
271 static handle cast(T &&src, return_value_policy policy, handle parent) {
272 dict d;
273 return_value_policy policy_key = policy;
274 return_value_policy policy_value = policy;
275 if (!std::is_lvalue_reference<T>::value) {
276 policy_key = return_value_policy_override<Key>::policy(policy_key);
277 policy_value = return_value_policy_override<Value>::policy(policy_value);
278 }
279 for (auto &&kv : src) {
280 auto key = reinterpret_steal<object>(
281 key_conv::cast(detail::forward_like<T>(kv.first), policy_key, parent));
282 auto value = reinterpret_steal<object>(
283 value_conv::cast(detail::forward_like<T>(kv.second), policy_value, parent));
284 if (!key || !value) {
285 return handle();
286 }
287 d[std::move(key)] = std::move(value);
288 }
289 return d.release();
290 }
291
292 PYBIND11_TYPE_CASTER(Type,
293 io_name("collections.abc.Mapping", "dict") + const_name("[")

Callers

nothing calls this directly

Calls 4

moveFunction · 0.85
releaseMethod · 0.80
castFunction · 0.70
handleFunction · 0.70

Tested by

no test coverage detected