| 248 | |
| 249 | template <typename PtrType, typename Class> |
| 250 | void construct_from_shared_ptr(value_and_holder &v_h, |
| 251 | std::shared_ptr<PtrType> &&shd_ptr, |
| 252 | bool need_alias) { |
| 253 | static_assert(std::is_same<PtrType, Cpp<Class>>::value |
| 254 | || std::is_same<PtrType, const Cpp<Class>>::value, |
| 255 | "Expected (const) Cpp<Class> as shared_ptr pointee"); |
| 256 | auto *ptr = shd_ptr.get(); |
| 257 | no_nullptr(ptr); |
| 258 | if (Class::has_alias && need_alias && !is_alias<Class>(ptr)) { |
| 259 | throw type_error("pybind11::init(): construction failed: returned std::shared_ptr pointee " |
| 260 | "is not an alias instance"); |
| 261 | } |
| 262 | // Cast to non-const if needed, consistent with internal design |
| 263 | auto smhldr |
| 264 | = smart_holder::from_shared_ptr(std::const_pointer_cast<Cpp<Class>>(std::move(shd_ptr))); |
| 265 | v_h.value_ptr() = const_cast<Cpp<Class> *>(ptr); |
| 266 | v_h.type->init_instance(v_h.inst, &smhldr); |
| 267 | } |
| 268 | |
| 269 | template <typename Class, detail::enable_if_t<is_smart_holder<Holder<Class>>::value, int> = 0> |
| 270 | void construct(value_and_holder &v_h, std::shared_ptr<Cpp<Class>> &&shd_ptr, bool need_alias) { |
nothing calls this directly
no test coverage detected