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

Function construct_from_shared_ptr

include/pybind11/detail/init.h:250–267  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

248
249template <typename PtrType, typename Class>
250void 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
269template <typename Class, detail::enable_if_t<is_smart_holder<Holder<Class>>::value, int> = 0>
270void construct(value_and_holder &v_h, std::shared_ptr<Cpp<Class>> &&shd_ptr, bool need_alias) {

Callers

nothing calls this directly

Calls 4

no_nullptrFunction · 0.85
moveFunction · 0.85
init_instanceMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected