75 bool from_python(handle src, uint8_t flags, cleanup_list *cleanup)
noexcept {
77 if (!caster.from_python(src, flags, cleanup))
return false;
79 Td *ptr = caster.operator
Td *();
80 if constexpr (has_shared_from_this_v<T>) {
82 if (
auto sp = ptr->weak_from_this().lock()) {
84 value = boost::static_pointer_cast<T>(std::move(sp));
93 value = boost::static_pointer_cast<T>(
99 static handle
from_cpp(
const Value &value, rv_policy,
100 cleanup_list *cleanup)
noexcept {
104 Td *ptr = (
Td *)value.get();
105 const std::type_info *type = &
typeid(
Td);
107 constexpr bool has_type_hook =
108 !std::is_base_of_v<std::false_type, type_hook<Td>>;
109 if constexpr (has_type_hook) type = type_hook<Td>::get(ptr);
111 if constexpr (!std::is_polymorphic_v<Td>) {
112 result = nb_type_put(type, ptr, rv_policy::reference, cleanup, &is_new);
114 const std::type_info *type_p =
115 (!has_type_hook && ptr) ? &
typeid(*ptr) :
nullptr;
117 result = nb_type_put_p(type, type_p, ptr, rv_policy::reference, cleanup,
122 boost::shared_ptr<void> pp;
123 if constexpr (std::is_const_v<T>)
124 pp = boost::static_pointer_cast<void>(
125 boost::const_pointer_cast<Td>(value));
127 pp = boost::static_pointer_cast<void>(value);