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

Function cast

include/pybind11/cast.h:1677–1691  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1675 && !detail::is_same_ignoring_cvref<T, PyObject *>::value,
1676 int> = 0>
1677T cast(const handle &handle) {
1678 using namespace detail;
1679 constexpr bool is_enum_cast = type_uses_type_caster_enum_type<intrinsic_t<T>>::value;
1680 static_assert(!cast_is_temporary_value_reference<T>::value || is_enum_cast,
1681 "Unable to cast type to reference: value is local to type caster");
1682#ifndef NDEBUG
1683 if (is_enum_cast && cast_is_temporary_value_reference<T>::value) {
1684 if (detail::global_internals_native_enum_type_map_contains(
1685 std::type_index(typeid(intrinsic_t<T>)))) {
1686 pybind11_fail("Unable to cast native enum type to reference");
1687 }
1688 }
1689#endif
1690 return cast_op<T>(load_type<T>(handle));
1691}
1692
1693// pytype -> pytype (calls converting constructor)
1694template <typename T, detail::enable_if_t<detail::is_pyobject<T>::value, int> = 0>

Callers 10

castMethod · 0.70
castMethod · 0.70
castMethod · 0.70
castMethod · 0.70
cast_implMethod · 0.70
castMethod · 0.70
object_or_castFunction · 0.70
make_tupleFunction · 0.70
arg_vMethod · 0.70
processFunction · 0.70

Calls 6

moveFunction · 0.85
ptrMethod · 0.80
inc_refMethod · 0.80
releaseMethod · 0.80
handleFunction · 0.70

Tested by

no test coverage detected